Search code examples
mysqlsqlreserved-words

Confused with selecting data from db in mysql


I have 2 tables: PLAYER and GROUP.

When I call:

SELECT * FROM PLAYER

Everything is OK but when I call:

SELECT * FROM GROUP

There is error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP' at line 1`

I don't understand why there is such error.


Solution

  • GROUP is a reserved keyword . You have to escape it, like so

      SELECT * FROM `GROUP`
    

    Things to note:

    • It is highly recommended not to name the table group, it is better to use the plural Groups.
    • Also, try to avoid *.