Backticks
suggest changeBackticks usage
There are many examples where backticks are used inside a query, but for many people it is still unclear when to use them.
Backticks are mainly used to prevent an error called “MySQL reserved word”. When making a table in PHPmyAdmin you are sometimes faced with a warning or alert that you are using a “MySQL reserved word”.
For example when you create a table with a column named “group” you get a warning. This is because you can make the following query:
SELECT student_name, AVG(test_score) FROM student GROUP BY group
To make sure you don’t get an error in your query you have to use backticks so your query becomes:
SELECT student_name, AVG(test_score) FROM student GROUP BY `group`
Table
Not only column names can be surrounded by backticks, but also table names. For example when you need to JOIN multiple tables.
SELECT `users`.`username`, `groups`.`group` FROM `users`
Easier to read
Backticks around table and column names can also make the query easier to read.
For example, when you write queries in lower case:
select student_name, AVG(test_score) from student group by group
select `student_name`, AVG(`test_score`) from `student` group by `group`
Please see the MySQL Manual page entitled Keywords and Reserved Words. The ones marked (R) are reserved words. The others are keywords. Reserved words need special caution.