To get some starting number of characters from the data stored in a MySQL table column, we can use the MySQL LEFT() function. It will return the number of characters specified as its argument. We need to provide the name of the column containing the specific record from which we want to get the starting character as its first parameter. To demonstrate this, let's take an example of a table named "examination_btech" which contains the exam details of the following students -
mysql> Select * from examination_btech; +-----------+----------+--------+ | RollNo | Name | Course | +-----------+----------+--------+ | 201712001 | Rahul | B.tech | | 201712002 | Raman | B.tech | | 201712003 | Sahil | B.tech | | 201712004 | Shalini | B.tech | | 201712005 | Pankaj | B.tech | | 201712006 | Mohan | B.tech | | 201712007 | Yash | B.tech | | 201712008 | digvijay | B.tech | | 201712009 | Gurdas | B.tech | | 201712010 | Preeti | B.tech | +-----------+----------+--------+ 10 rows in set (0.00 sec)
Now, if we want to get the first six characters from a series of rolls, Then it can be done with the help of the LEFT() function, as shown below-
mysql> Select LEFT(RollNo, 6) FROM examination_btech; +-----------------+ | LEFT(RollNo, 6) | +-----------------+ | 201712 | | 201712 | | 201712 | | 201712 | | 201712 | | 201712 | | 201712 | | 201712 | | 201712 | | 201712 | +-----------------+ 10 rows in set (0.00 sec)
The above is the detailed content of How can we get some starting number of characters from the data stored in a MySQL table column?. For more information, please follow other related articles on the PHP Chinese website!