How do i save double quotes in mysql?

To insert records with double quotes, use the backslash [\] as in the below syntax −

Syntax

insert into yourTableName values['\"yourValue\"'];

Let us first create a table −

mysql> create table DemoTable
   -> [
   -> Name varchar[20]
   -> ];
Query OK, 0 rows affected [0.63 sec]

Insert some records in the table using insert command −

mysql> insert into DemoTable values['\"John\"'];
Query OK, 1 row affected [0.17 sec]
mysql> insert into DemoTable values['\"Chris\"'];
Query OK, 1 row affected [0.11 sec]
mysql> insert into DemoTable values['\"Adam Smith\"'];
Query OK, 1 row affected [0.14 sec]
mysql> insert into DemoTable values['\"Carol\"'];
Query OK, 1 row affected [0.20 sec]

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output. The double quotes around the records can be easily seen −

+--------------+
| Name         |
+--------------+
| "John"       |
| "Chris"      |
| "Adam Smith" |
| "Carol"      |
+--------------+
4 rows in set [0.00 sec]

Updated on 12-Dec-2019 05:20:26

  • Related Questions & Answers
  • Find records with double quotes in a MySQL column?
  • How to insert date in single quotes with MySQL date formats?
  • How to print double quotes with the string variable in Python?
  • How to prevent MySQL double insert [duplicate entry]?
  • Single quotes vs. double quotes in C or C++
  • Single and Double Quotes in Perl
  • MySQL query to insert multiple records quickly
  • How to add a string containing double quote to records in MySQL?
  • Insert records from multiple tables in MySQL
  • How to include quotes in comma separated column with MySQL?
  • The easiest way to insert date records in MySQL?
  • Escaping quotes while inserting records in MongoDB?
  • How to escape single quotes in MySQL?
  • Is there a PHP function that only adds slashes to double quotes NOT single quotes
  • Use UNION ALL to insert records in two tables with a single query in MYSQL

Using Backticks, Double Quotes, and Single Quotes when querying a MySQL database can be boiled down to two basic points.

  1. Quotes [Single and Double] are used around strings.
  2. Backticks are used around table and column identifiers.

Double Quotes

Using double quotes here is some input and output examples:

SELECT "test", "'test'", "''test''", "te""st";

The output looks like this:

Wrapping single quotes inside of double quotes will cancel out the expected behavior of the single quotes in the MySQL Query and instead treat it as part of the string. This can be seen in columns 2 and 3 in the example above.

Inserting two double quotes in the middle of the string will cancel out one of them.

Single Quotes

Using single quotes here is some input and output examples:

SELECT 'test', '"test"', '""test""', 'te''st';

The output looks like this:

As shown in the demonstration above, single quotes behave the same way as double quotes in these contexts.

Using Single Quotes and Double Quotes Together

Often times there will be a contraction in a string, or a direct quote. In situations like in NPS survey reports or other customer feedback forms this is often the case. In these cases using double quotes to wrap a text string that contains a contraction like They’ve will keep the single quote in the string as an apostrophe.

In this case presenting a string with a contraction should look like this:

SELECT "They've found this tutorial to be helpful"

The output looks like this:

Or, if you need to use double quotes to present a customer feedback quote in the string, you can use single quotes to wrap the whole string.

SELECT 'They responded, "We found this tutorial helpful"'

If you need to use single quotes and double quotes in a string that contains both a contraction and a quote, you will need to use the backslash ‘' to cancel out the following character. For example: a string containing this ' will recognize the backslash as an instruction to cancel out the single quote’s syntactical meaning and instead insert it into the string as an apostrophe.

SELECT 'They\'ve responded, "We found this tutorial helpful"'

Backticks

Backticks are used in MySQL to select columns and tables from your MySQL source. In the example below we are calling to the table titled Album and the column Title. Using backticks we are signifying that those are the column and table names.

    SELECT `Album`.`Title`
    FROM `Album` AS `Album`
    GROUP BY `Album`.`Title`
    ORDER BY `Title` ASC
    LIMIT 10;

The backticks for column names may not be necessary though.

    SELECT Album.Title
    FROM Album AS Album
    GROUP BY Album.Title
    ORDER BY Title ASC
    LIMIT 10;

Both of these queries will return the same result.

Putting it all together

The following query will use all we’ve learned here, including double quotes, single quotes, and backticks.

SELECT 'They\'ve responded, "We found this tutorial helpful"' as `Response`

Will return:

Does MySQL support double quotes?

Double quotes are supported by MySQL for string values as well, but single quotes are more widely accepted by other RDBMS, so it is a good habit to use single quotes instead of double. MySQL also expects DATE and DATETIME literal values to be single-quoted as strings like '2001-01-01 00:00:00' .

How do I add a quote in MySQL?

QUOTE [] function in MySQL The string is returned enclosed by single quotation marks and with each instance of backslash [\], single quote ['], ASCII NULL, and Control+Z preceded by a backslash.

How do you handle double quotes in SQL?

Use two single quotes to escape them in the sql statement. The double quotes should not be a problem: SELECT 'How is my son''s school helping him learn? "Not as good as Stack Overflow would!"'

Can you use double quotes in SQL?

Double quotes generally aren't used in SQL, but that can vary from database to database. Stick to using single quotes. That's the primary use anyway..
Double quotes are usually used to object names [e.g. column name "First name"]. ... .
No. ... .
158. ... .
You should use double quotes for identifiers..

Chủ Đề