LEFT function in SQL

The LEFT() function in SQL is used to extract a specified number of characters from the left side of a string.

SQL Syntax

LEFT(string, number_of_characters)

Example: Let's we have a table Employees.

Table: Employees

IDName
1Ashish
2Priya
3Rahul
4Sneha

Now we want to extract the first 3 characters from each employee's name .

SQL

SELECT LEFT(name, 3) AS ShortName
FROM employees;  

If the name is "Ashish", the result will be "Ash".

The result of the above query is shown below:

IDNameShortName
1AshishAsh
2PriyaPri
3RahulRah
4SnehaSne