0

e.g. query is

SELECT `username`, `uid`,`email` from profile  and `id`='0';

and

SELECT username, uid,email from profile  and id='0';

both will yeild same result. so why we should use or not use ` in mysql query.

Naftali
  • 144,921
  • 39
  • 244
  • 303
  • 1
    You use ` around the table or column name that is a MySQL reserved word; otherwise MySQL can't differentiate... e.g. `select id, desc from mytable` will cause problems because `desc` is a reserved word – Mark Baker Aug 05 '13 at 13:40

3 Answers3

0

The backtick and nonbacktick versions that you show both do the same thing.

The main reason one would use backticks is to escapse a MySQL reserved word or a column with a space in the column name.

Naftali
  • 144,921
  • 39
  • 244
  • 303
0

You can name your columns anything if you use ` to delimit them. You could call it timestamp, restrict or any other keyword. Or you could call it 60000. Or you could call it domain of the flying spaghetti monster if you really wanted.

SELECT `domain of the flying spaghetti monster` FROM `table`

has to be the weirdest select query I've seen!

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
0

Backticks will allow you use mysql reserved words as column names. Which is not a good idea to use anyways.

Example:

SELECT from, insert,delete from profile  and `id`='0'; will not work

SELECT `from`, `insert`,`delete` from profile  and `id`='0'; will work
Aris
  • 4,643
  • 1
  • 41
  • 38