
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we get some starting number of characters from the data stored in a MySQL table’s column?
To get some starting number of characters from the data stored in the MySQL table’s column, we can use MySQL LEFT() function. It will return the number of characters specified as its argument. We need to provide the name of the column, having the particular record from which we want to get starting characters, as its first argument. To demonstrate it we are taking the example of a table named ‘examination_btech’ having the following examination details of 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 the series of roll no then it can be done with the help of LEFT() function as follows −
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)
- Related Articles
- How can we get some last number of characters from the data stored in a MySQL table’s column?
- How can we copy data with some condition/s from existing MySQL table?
- How can we add day/s in the date stored in a column of MySQL table?
- How can I use MySQL OCTET_LENGTH() function to count the number of characters stored in a data column?
- How can we modify column/s of MySQL table?
- How can you retrieve a particular number of records from a table starting from some specified row number in Python MySQL?
- How can we write MySQL stored procedure to select all the data from a table?
- How can we export some field(s) from MySQL table into a text file?
- How can we export some field(s) from MySQL table into a CSV file?
- How can we create a MySQL stored function that uses the dynamic data from a table?
- How can we remove a column from MySQL table?
- How can we change the data type of the column in MySQL table?
- How can we add a time interval to date stored in a column of MySQL table?
- How can we create a new MySQL table by selecting specific column/s from another existing table?
- How to repeat the values stored in a data column of MySQL table?

Advertisements