0

hey guys was hoping you could help me out,

Not sure if I always had this problem or if its new, in phpmyadmin in the sql tab, the apostrophe it recognizes is different from what i type, for example,

when i type, it is

SELECT * FROM 'table'

this gives me an error, so instead I have to like copy/paste the inverted commas of some prebuilt query so that it looks like

SELECT * FROM `table`

see how the apostrophes are different? any way I can fix this?

also, i have seen many queries on the web, and i think even queries i call from php dont require table names to have apostrophes. But when write it in phpmyadmin, I can do queries without table names having apostrophes?

thanks in advance.

Ahmed-Anas
  • 5,471
  • 9
  • 50
  • 72

5 Answers5

6

In MYSQL, table is a reserved keyword. If you want to use reserved keywords in mysql in query, you have to enclose them in backtick(`).

As table is reserved keyword you query should be

SELECT * FROM `table`

Regarding single quote ('), in mysql, it represents string value.

SELECT *, 'table' FROM `table`;

Demo

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
2

You should only need to quote table names when they conflict with a reserved word.

Also:

` = Grave accent, or (because someone needed to invent a word) backtick
' = Apostrophe, or straight single quote
Gnarfoz
  • 3,146
  • 1
  • 17
  • 15
1

You dont need apostrophe on table name.

Kristijan
  • 323
  • 6
  • 11
1

You should use ` in cases that your table/field name is a reserve word eg:

SELECT `distinct`, myfields FROM mytable

note that distinct is an sql command so you need to put the `.

SELECT * FROM `table`

table here should be inside `.

Bob
  • 1,489
  • 1
  • 16
  • 28
0

There are two different characters, the backtick and the single quote. Table and column names can be surrounded by the backtick, strings can be surrounded by quotes. There is nothign to fix :D

Nanne
  • 64,065
  • 16
  • 119
  • 163