Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to get first N characters from a MySQL column?
Use SUBSTRING() to get first N characters from a MySQL column. Let us first create a table −
mysql>create table DemoTable ( Information text ); Query OK, 0 rows affected (2.63 sec)
Insert records in the table using insert command −
mysql>insert into DemoTable values('MySQL is a structured query language');
Query OK, 1 row affected (0.13 sec)
Following is the query to display all records from the table using select statement −
mysql>select *from DemoTable;
This will produce the following output −
+--------------------------------------+ | Information | +--------------------------------------+ | MySQL is a structured query language | +--------------------------------------+ 1 row in set (0.00 sec)
Here is the query to get first N characters from the column. In this case, we are selecting the first 10 characters −
mysql>select substring(Information,1,10) from DemoTable;
This will produce the following output −
+-----------------------------+ | substring(Information,1,10) | +-----------------------------+ | MySQL is a | +-----------------------------+ 1 row in set (0.00 sec)
Advertisements
