
- 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
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)
- Related Articles
- MySQL query to get string from one column and find its position in another column with comma separated values?
- MySQL query to retrieve records from the part of a comma-separated list?
- Get values from all rows and display it a single row separated by comma with MySQL
- Searching from a comma separated MySQL column?
- MySQL query to fetch specific records matched from an array (comma separated values)
- MySQL query to find a value in a set of values separated by comma in a custom variable
- How to sum a comma separated string (string with numbers) in MySQL?
- How to create a comma separated string from a list of string in C#?
- MySQL query to search between comma separated values within one field?
- Remove specific word in a comma separated string with MySQL
- How to use a comma-separated string in an `IN ()` in MySQL?
- How to display data from a MySQL column separated by comma?
- Count values from comma-separated field in MySQL?
- C++ Program to take out integer from comma separated string
- Count the number of comma’s in every record from a comma-separated value column in MySQL

Advertisements