Salman Quader Salman Quader - 2 years ago 61
SQL Question

what is different between FROM `tableName` and FROM tableName?

1) "select * from `union` WHERE `thanaId`='$thana_id'" // it's working
2) "select * from union WHERE thanaId='$thana_id'" // it's not working

1 sql query run properly but 2 Sql query can't execute properly. what is meaning of [``]..

what is different between 1 sql query and 2 sql query?

Answer Source

The backtick encases the string to be treated as a string named literal rather than be interpreted by the MySQL engine. The word union is a reserved / keyword and so MYSQL will be expecting a different syntax because it won't realise that you're using this word as a name identifier.

You would do very well to read and learn this page from the MySQL manual. Every word from the list on this page should be encased in backticks in MySQL queries if you want MySQL to treat it as a name.

It's also useful as much as possible to not name columns/tables with Keywords or reserved words!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download