0 votes
1 view
in SQL by (20.3k points)

I have a SQL column with a length of 6. Now want to take only the first char of that column. Is there any string function in SQL to do this?

1 Answer

0 votes
by (40.4k points)

You can use MYSQL SUBSTRING () Function in this way:

Have a look at this video to understand where to use String Functions with syntax and examples.

LEFT (Col_Name, 1)

Or

SELECT SUBSTRING(Col_Name, 1, 1) AS ExtractString;

Parameters used in the SUBSTRING method is as follows:

        1.  Col_Name: This is required to extract the string.

       2.  1: This is required for start position. Where 1st position in the string is 1.

       3. 1: This is nothing but length which is required to extract the no of characters. It must be greater than equal to 1(or positive no).

Note: LEFT() and SUBSTRING() methods are equal.

You can master these queries and become proficient in SQL queries by enrolling in an industry-recognized SQL certification.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...