Search code examples
sqlbackticks

Why are SQL fieldnames sometimes spelled like `this`?


What's the difference between

SELECT * FROM `this`

and

SELECT * FROM this

?


Solution

  • The former is escaped, the latter isn't. Consider:

    SELECT * FROM `FROM`
    

    On systems where the the backtick is an escape, that would select from a table called FROM (whereas without the backticks, it's a syntax error). Some systems use square brackets instead, e.g., SELECT * FROM [FROM].