Home > Database > Mysql Tutorial > How can we get some starting number of characters from the data stored in a MySQL table column?

How can we get some starting number of characters from the data stored in a MySQL table column?

PHPz
Release: 2023-09-05 18:45:12
forward
1434 people have browsed it

我们如何从存储在 MySQL 表列中的数据中获取一些起始字符数?

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template