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
-
Economics & Finance
Selected Reading
MySQL query to get a single value from position of comma-separated string?
For this, use SUBSTRING_INDEX(). Let us first create a table −
mysql> create table DemoTable1615 -> ( -> ListOfSubject text -> ); Query OK, 0 rows affected (0.81 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1615 values('Python,Java,MySQL,MongoDB,C,C++,ASP.net');
Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1615;
This will produce the following output −
+-----------------------------------------+ | ListOfSubject | +-----------------------------------------+ | Python,Java,MySQL,MongoDB,C,C++,ASP.net | +-----------------------------------------+ 1 row in set (0.00 sec)
Here is the query to get a single value from position of comma-separated-string −
mysql> select substring_index(substring_index(ListOfSubject, ',', 4), ',', - 1) as Position from DemoTable1615;
This will produce the following output −
+----------+ | Position | +----------+ | MongoDB | +----------+ 1 row in set (0.00 sec)
Advertisements
