HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlCritical

Benefits of using backtick (`) in MySQL queries?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
mysqlbacktickbenefitsusingqueries

Problem

In MySQL we can create queries with or without the backtick (``) symbol. Example:

  • SELECT * FROM TEST;



  • SELECT * FROM TEST;



Both works fine in mysql-console.

Is there any technical difference between them?

Is there any benefit using (
``) over over simple queries?

Solution

They are called quoted identifiers and they tell the parser to handle the text between them as a literal string. They are useful for when you have a column or table that contains a keyword or space. For instance the following would not work:

CREATE TABLE my table (id INT);


But the following would:

CREATE TABLE `my table` (id INT);


Also, the following would get an error, because COUNT is a reserved keyword:

SELECT count FROM some_table


But the following would be parsed correctly:

SELECT `count` FROM some_table


I hope this helps you.

Code Snippets

CREATE TABLE my table (id INT);
CREATE TABLE `my table` (id INT);
SELECT count FROM some_table
SELECT `count` FROM some_table

Context

StackExchange Database Administrators Q#23129, answer score: 50

Revisions (0)

No revisions yet.