[MySQL] 予約語でハマる - ERROR 1064 (42000): 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 'xxx' at line 1

Tadashi Shigeoka ·  Sun, January 20, 2013

MySQL でどう見ても大丈夫そうな SQL を実行したら文法エラーが発生しました。

MySQL

ERROR 1064 (42000): You have an error in your SQL syntax;

mysql> SELECT * FROM addresses ORDER BY primary;
ERROR 1064 (42000): 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 'primary' at line 1

primary は予約語

primary が予約語らしいので、シングルクォートで囲んで実行すれば大丈夫でした。

mysql> SELECT * FROM addresses ORDER BY 'primary';

参考情報