
- 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
Which MySQL function can be used to append values of a column with single quotes?
MySQL QUOTE() function can be used to append values of a column with single quotes. For this, we must have to pass column name as the argument of QUOTE() function. Data from ‘Student’ table is used to demonstrate it as follows
Example
mysql> Select Name, ID, QUOTE(Subject)AS Subject from Student; +---------+------+-------------+ | Name | ID | Subject | +---------+------+-------------+ | Gaurav | 1 | 'Computers' | | Aarav | 2 | 'History' | | Harshit | 15 | 'Commerce' | | Gaurav | 20 | 'Computers' | | Yashraj | 21 | 'Math' | +---------+------+-------------+ 5 rows in set (0.00 sec)
In contrast, it can also be done with the help of CONCAT() function as follows −
mysql> Select Name, ID, CONCAT('''',Subject,'''')AS Subject from Student; +---------+------+-------------+ | Name | ID | Subject | +---------+------+-------------+ | Gaurav | 1 | 'Computers' | | Aarav | 2 | 'History' | | Harshit | 15 | 'Commerce' | | Gaurav | 20 | 'Computers' | | Yashraj | 21 | 'Math' | +---------+------+-------------+ 5 rows in set (0.00 sec)
For this purpose QUOTE() function is very easy to use.
- Related Articles
- How to concatenate two column values into a single column with MySQL. The resultant column values should be separated by hyphen
- How can column data values of a table be compared using MySQL STRCMP() function?
- Append special characters to column values in MySQL
- How can MySQL COALESCE() function be used with MySQL SUM() function to customize the output?
- Inserting multiple parameter values into a single column with MySQL?
- Can a number be used to name a MySQL table column?
- How can MySQL REPLACE() function be used with WHERE clause?
- How can CONCAT() function be used with MySQL WHERE clause?
- How wildcard characters can be used with MySQL CONCAT() function?
- How can CONCAT_WS() function be used with MySQL WHERE clause?
- How LOCATE() function can be used with MySQL WHERE clause?
- MySQL query to sort column values and ignoring quotes on one of the values
- How can I update MySQL table after quoting the values of a column with a single quote?
- Using MySQL keywords in a query surrounded with single quotes?
- Find records with double quotes in a MySQL column?

Advertisements