left String function in MySQL
The output of this is here
Now we will apply this to our student table on name field
We will get left 5 chars of name field of student table.
Example : Taking out the userid part of email address.We can use LEFT function to get the userid part of the email address. Before that we will find out the position of @ char inside email address by using locate function. The output of locate function ( which gives the location of @ ) we will use to take the left most characters. Please note that there are several ways to solve this problem and this is one of the way only.Let us first locate the position of @ in our email address.
This will give us a number for each record which we can use to get the userid part.
This will give us Userid part but will end with one extra @ added to it. Now here is the final one we can get by subtracting 1 from the output of locate function.
![]()
This article is written by plus2net.com team.
https://www.plus2net.com
![]() ▼ More on String |