MySQL LEFT() Function

The LEFT() function in MySQL returns a specific number of characters from the start (left side) of a string.

Tutorials dojo strip

MySQL LEFT Function Syntax

LEFT(string, number_of_chars)

MySQL LEFT Function Example

This query extracts the first 3 characters from the string “SQL Tutorial”:

SELECT LEFT("SQL Tutorial", 3) AS ExtractString;

Note: This example works in MySQL, but does not work in SQLite or the TechKubo Playground.

MySQL LEFT Function Parameters

ParameterDescription
stringRequired. The string to extract from
number_of_charsRequired. Number of characters to extract from left

MySQL LEFT Function Patients Table Example

This query attempts to extract the first 2 characters from each first_name in the Patients table:

SELECT LEFT(first_name, 2) AS Initials
FROM Patients;

Note: This example works in MySQL, but does not work in SQLite or the TechKubo Playground.

MySQL LEFT Function Notes

  • If the number of characters is greater than the string length, the whole string is returned.
  • In SQLite (including TechKubo), use SUBSTR(column, 1, N) instead of LEFT().
  • Available in MySQL 4.0 and later.

Tutorials dojo strip
Scroll to Top