LEFT() function returns a substring that consists of a specified number of leftmost characters from a string.
Here is the syntax of the
In this syntax:
- First, specify the source string (
string) from which to extract the substring.
- Second, specify the number of leftmost characters (
length) to be extracted.
This example returns the first three characters of the string
SELECT LEFT('IBM Db2',3) result FROM sysibm.sysdummy1;
The following shows the output:
RESULT ------- IBM
See the following
authors tables from the sample database:
This example uses the
LEFT() function shows the number of the last names for each initial (A, B, C…):
SELECT LEFT(last_name,1) Initial, COUNT(last_name) FROM authors GROUP BY LEFT(last_name,1);
The output is as follows:
In this tutorial, you have learned how to use the Db2
LEFT() function to return the number of leftmost characters of a string.