Backticks and regular quotes (both single and double) have distinct meanings in SQL. Quotes indicate a literal string, whereas backticks are quoted identifiers. This isn’t specific to WordPress, but rather a general way in SQL of quoting columns or tables.
For example, imagine you’re running a query comparing two columns:
SELECT * FROM wp_posts WHERE post_name = post_title
If you compare with single quotes ('post_name' = 'post_title'
) this would compare the literal strings, which are never equal. However, with backticks, it would refer to the column.
Why use backticks at all? If a column is named the same as a reserved word in SQL, or contains a space, you need to quote it. For example, if you had a column called count
, you’d need to quote that every time you refer to it, as COUNT()
is a function (and hence, reserved word) in MySQL.
See also https://dba.stackexchange.com/questions/23129/benefits-of-using-backtick-in-mysql-queries