MySQL Order by boolean value tinyint

Issue

I am using mysql Ver 14.14 Distrib 5.5.31, for debian-linux-gnu (x86_64).

This query fails with a You have an error in your SQL syntax[...]near 'read ASC' message :

SELECT 'messages'.* FROM 'messages' WHERE 'messages'.'user_id' = 2 ORDER BY read ASC;

where the read column is a TINYINT(1) value generated by the Rails ActiveRecord interface to store boolean values.

The same action works when switching to postgresql, but i currently have no access to the pg generated queries.
Is there something wrong with the actual query? (maybe i cannot order by a tinyint) or should I file a bug report?

Solution

Read is reserve keyword in mysql
http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-5.html

you have to add ‘read’ ASC in your query

Answered By – naveen goyal

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published