Name

LEFT( )

Synopsis

LEFT(string, length)

This function returns characters from a string given in the first argument for the length specified in the second argument, starting from the left end of the string.

SELECT LEFT(home_telephone, 3) AS 'Area Code'
FROM students GROUP BY 'Area Code';

This SQL statement extracts the first three digits of the telephone number of each student, which is the telephone area code, and then groups the results by the Area Code alias to determine the telephone area codes in which students reside.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.