tags:

views:

32

answers:

2

Hi,

when I write a sql statement in php, i usualy write it as below

SELECT COUNT(*) FROM catalogsearch_query AS main_table

but I found that some people write sql statement like

SELECT COUNT(*) FROM `catalogsearch_query` AS `main_table`

do I have to use ` ?

+5  A: 

You don't have to use backticks. However when you're using reserved keywords as table or field names, then you have to enclose them in backticks for them to work.

reko_t
A: 

From MySql docs:

Database, table, index, column, and alias names are identifiers. An identifier may be quoted or unquoted. If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it.

We use the backtick ` for quoting.

codaddict