I have a problem with sql query in php:
select
user, name, outlet, switch, port, vlan, mac, status
from access where
user like '%'
and name like '%'
and outlet like '%'
and switch like '%'
and port like '%'
and vlan like '%'
and mac like '%'
and status like '%'
order by 'user';
When running query on MySQL client version: 5.1.36 query doesn’t work totally (ORDER BY won’t work), however when running SAME query on MySQL client version: 4.1.13, ORDER BY works!
I have checked nearly all manuals about ORDER BY, WHERE, LIKE commands, but no result. No mention about version differences, etc..
You have to remove the quotes from
userin theORDER BYclause. This is what is causing theORDER BYnot working as expected, because you can use any expression in theORDER BYclause, and the'user'in quotes is being considered an expression (constant) instead of a column name.Test case (MySQL 5.1.45):