
Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: August 28, 2025
In this tutorial, we’ll explore the correct usage of single quotes, double quotes, and backticks in MySQL.
Although appearing similar, these three types of quotation marks serve very different purposes in MySQL. Understanding the correct use of each is essential for writing clear, error-free SQL queries and avoiding common pitfalls, especially when dealing with strings, identifiers, and reserved keywords.
We primarily use single quotes (‘…’) for string literals in MySQL. Whenever we need to specify a fixed string value, such as a name, date, or text data, we should use single quotes:
SELECT * FROM users WHERE name = 'Lee Xin';
MySQL interprets everything inside single quotes as a literal string. If our string contains a single quote character, then we must escape it with another single quote:
SELECT 'It''s a sunny day';
This escaping prevents syntax errors and ensures that the string is correctly processed. We can test this query with one and two quotes using online MySQL compiler. The results will look like this:
> SELECT 'It's a sunny day';
ERROR 1064 ...
> SELECT 'It''s a sunny day';
+-----------+
+ It's a sunny day
As we can see, it outputs an error when we use only a single quote inside single quotes that define our string.
Double quotes (“…”) have a special role depending on the SQL mode.
By default, in MySQL’s ANSI_QUOTES mode, double quotes are the same as backticks. It means they identify column or table names. In a non-ANSI_QUOTES mode, double quotes can sometimes act like single quotes for string literals, but relying on this behavior can cause compatibility issues across environments.
For example, lets assume we have the following query:
SELECT "column" FROM table WHERE foo = "bar";
Here we can have two outcomes:
The best practice is to avoid using double quotes so that our code becomes independent of SQL modes.
We use backticks (`…`) for delimiting identifiers such as column names, table names, and database names that might otherwise cause problems because they are reserved keywords, contain spaces, or special characters:
SELECT `order`, `user name` FROM `sales data`;
Without backticks, “order” would be interpreted as a reserved keyword, and “user name” would be invalid due to the space. Backticks ensure that MySQL treats the enclosed text as an identifier exactly as written.
In this article, we clarified when to use single quotes, double quotes, and backticks in MySQL.
Single quotes are the standard for string literals. Double quotes are best avoided, as their meaning shifts depending on the SQL mode. Backticks remain the safest and most reliable choice for column, table, and database names that include reserved keywords, spaces, or special characters.