- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to include quotes in comma separated column with MySQL?
Let us first create a −
mysql> create table DemoTable1407 -> ( -> Name text -> ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1407 values('John,Bob'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1407 values('Carol,David,Adam'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1407 values('Mike,Sam,Chris'); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select −
mysql> select * from DemoTable1407;
This will produce the following output −
+------------------+ | Name | +------------------+ | John,Bob | | Carol,David,Adam | | Mike,Sam,Chris | +------------------+ 3 rows in set (0.00 sec)
Here is the query to include quotes in comma separated column with MySQL −
mysql> select concat("'", replace(Name, ",", "','"), "'") AS IncludingQuotes from DemoTable1407;
This will produce the following output −
+------------------------+ | IncludingQuotes | +------------------------+ | 'John','Bob' | | 'Carol','David','Adam' | | 'Mike','Sam','Chris' | +------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- Searching from a comma separated MySQL column?
- How to display data from a MySQL column separated by comma?
- Find specific records from a column with comma separated values in MySQL
- How to fetch random rows in MySQL with comma separated values?
- How to sum a comma separated string (string with numbers) in MySQL?
- MySQL query to get string from one column and find its position in another column with comma separated values?
- Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?
- Remove specific word in a comma separated string with MySQL
- Find integer in text data (comma separated values) with MySQL?
- Display all the column values in a single row separated by comma in MySQL?
- How to use a comma-separated string in an `IN ()` in MySQL?
- How to set a comma separated list as a table in MySQL?
- How to search for particular strings between comma separated values in MySQL?
- Find records with double quotes in a MySQL column?
- Count values from comma-separated field in MySQL?

Advertisements