
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get the substring of a column in MySQL
Use the SUBSTR() method to get the substring of a column.
Let us first create a table −
mysql> create table DemoTable -> ( -> Title text -> ); Query OK, 0 rows affected (0.74 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('This is a MySQL Database'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Java is an Object Oriented Programming Language'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable ;
Output
This will produce the following output −
+-------------------------------------------------+ | Title | +-------------------------------------------------+ | This is a MySQL Database | | Java is an Object Oriented Programming Language | +-------------------------------------------------+ 2 rows in set (0.00 sec)
Here is the query to select substring of a column −
mysql> SELECT distinct(substr(Title, 1, 8)) from DemoTable;
Output
This will produce the following output −
+-----------------------+ | (substr(Title, 1, 8)) | +-----------------------+ | This is | | Java is | +-----------------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- Get the index of last substring in a given string in MySQL?
- How to substring value in a MySQL table column?
- Get the sum of a column in all MySQL rows?
- How can we extract a substring from the value of a column in MySQL table?
- Get the count of only unique rows in a MySQL column?
- Get the maximum value of a column with MySQL Aggregate function
- Get the count of duplicate values from a single column in MySQL?
- MySQL query to get the count of distinct records in a column
- Get the substring after the first occurrence of a separator in Java
- Get the substring before the last occurrence of a separator in Java
- Get the first occurrence of a substring within a string in Arduino
- Get the last occurrence of a substring within a string in Arduino
- What is the syntax in MySQL to get the column names of a table?
- How to get substring of a string in jQuery?
- How to get the count of a specific value in a column with MySQL?
Advertisements