tags:

views:

33

answers:

2

I am using mysql and the following two sqls produce different result.

SELECT developers.* FROM "developers" ORDER BY id DESC LIMIT 1
SELECT developers.* FROM "developers" ORDER BY 'id DESC' LIMIT 1

I thought that quoting order by should not matter.

+9  A: 

By quoting the order you are ordering by the literal string 'id DESC', which would indeed change the result, since it's pretty meaningless - little different to saying ORDER BY 1

Paul Dixon
+4  A: 

ORDER BY 'id DESC' is saying "ORDER BY the constant string 'id DESC'". Don't quote the ORDER BY! :)

Will A