如何选择具有表名:“组”的表?

mos*_*toh 7 mysql

我有一张桌子。表的名称是“组”

我运行这样的查询:

SELECT * FROM GROUP
Run Code Online (Sandbox Code Playgroud)

存在这样的错误:

Error Code: 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 
 LIMIT 0, 1000' at line 1
Run Code Online (Sandbox Code Playgroud)

有什么解决方案可以解决我的问题?

谢谢

son*_*que 11

使用反引号:

SELECT * FROM `GROUP`
Run Code Online (Sandbox Code Playgroud)

您还可以为您的表名设置别名以供以后在WHERE子句中使用,例如:

SELECT * FROM `GROUP` g WHERE g.id = 1
Run Code Online (Sandbox Code Playgroud)

  • 或者停止使用 [**RESERVED WORDS**](http://dev.mysql.com/doc/refman/5.7/en/keywords.html) 作为表名 (6认同)