user166891
user166891

Reputation: 139

MySQL Wrong ORDER BY

SELECT `player`.`cid`, `player`.`k`, `player`.`d`, `gg`.`gg_id`, `gg`.`name`, `gg`.`img`, `cc`.`cid`, `cc`.`name`, `cc`.`class`, `cc`.`gg_id`
FROM `player` 
LEFT JOIN `cc` ON `cc`.`cid` = `player`.`cid` 
LEFT JOIN `gg` ON `gg`.`gg_id` = `cc`.`gg_id` 
ORDER BY (`k`-`d`) DESC

i want to order by the K minus the D values, but im not getting it correctly what im a doing wrong? with or without DESC/ASC, its wrong

Upvotes: 2

Views: 930

Answers (1)

Jason George
Jason George

Reputation: 7002

Try:

SELECT (player.k-player.d), player.cid, player.k, player.d, gg.gg_id, gg.name, gg.img, cc.cid, cc.name, cc.class, cc.gg_idFROM player LEFT JOIN cc ON cc.cid = player.cid LEFT JOIN gg ON gg.gg_id = cc.gg_id ORDER BY (player.k-player.d) DESC

I did a quick query of my own and the results appear to be unordered (despite the fact the were) until I added the SELECT (player.k-player.d). MySQL also complained about ommiting the table name in the ORDER BY clause.

Upvotes: 1

Related Questions