Naguib Ihab
Naguib Ihab

Reputation: 4496

MySQL query error with a table named "order"

I have this problem but I just found out the solution so I'll write it here anyway in case anyone stumbles in it. This is my mysql query:

mysql_query("SELECT id FROM order ORDER BY id DESC LIMIT 1")

And the error I received was

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 'order ORDER BY id DESC LIMIT 1' at line 1

Upvotes: 2

Views: 2418

Answers (1)

Vignesh Kumar A
Vignesh Kumar A

Reputation: 28403

Order is reserved Word. You have to use like Enclose ORDER in back-ticks.

Try this

mysql_query("SELECT id FROM `order` ORDER BY id DESC LIMIT 1")

Reserved Words

Upvotes: 3

Related Questions