To get the last number of characters from the data stored in a MySQL table column, we can use the MySQL RIGHT() function. It will return the number of characters specified as argument. We need to provide the name of the column and the specific record from which we want to get the last 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 last three characters from a series of rolls then This can be done with the help of the RIGHT() function as shown below-
mysql> Select RIGHT(RollNo, 3) FROM examination_btech; +------------------+ | RIGHT(RollNo, 3) | +------------------+ | 001 | | 002 | | 003 | | 004 | | 005 | | 006 | | 007 | | 008 | | 009 | | 010 | +------------------+ 10 rows in set (0.00 sec)
The above is the detailed content of How can we get the last 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!