mcmuney Posted March 16, 2006 Share Posted March 16, 2006 How do you perform multiple sorts. For example "ORDER BY "X" DESC". What if I wanted to order first by x, then y. How would I do that...ORDER BY "X" DESC AND ORDER BY "Y" DESC??? Link to comment https://forums.phpfreaks.com/topic/5078-sorting/ Share on other sites More sharing options...
redarrow Posted March 16, 2006 Share Posted March 16, 2006 [!--quoteo(post=355539:date=Mar 16 2006, 01:10 AM:name=mcmuney)--][div class=\'quotetop\']QUOTE(mcmuney @ Mar 16 2006, 01:10 AM) [snapback]355539[/snapback][/div][div class=\'quotemain\'][!--quotec--]How do you perform multiple sorts. For example "ORDER BY "X" DESC". What if I wanted to order first by x, then y. How would I do that...ORDER BY "X" DESC AND ORDER BY "Y" DESC???[/quote]is this it according to myql[code]SELECT * FROM t1 ORDER BY key_part1 DESC, key_part2 ASC;[/code][code]You use ORDER BY on different keys: SELECT * FROM t1 ORDER BY key1, key2;You use ORDER BY on non-consecutive parts of a key: SELECT * FROM t1 WHERE key2=constant ORDER BY key_part2;You mix ASC and DESC: SELECT * FROM t1 ORDER BY key_part1 DESC, key_part2 ASC;The key used to fetch the rows is not the same as the one used in the ORDER BY: SELECT * FROM t1 WHERE key2=constant ORDER BY key1;You are joining many tables, and the columns in the ORDER BY are not all from the first [/code][a href=\"http://dev.mysql.com/doc/refman/5.1/en/order-by-optimization.html\" target=\"_blank\"]http://dev.mysql.com/doc/refman/5.1/en/ord...timization.html[/a]I tried lol Link to comment https://forums.phpfreaks.com/topic/5078-sorting/#findComment-17995 Share on other sites More sharing options...
wickning1 Posted March 16, 2006 Share Posted March 16, 2006 It's just "ORDER BY x ASC, y DESC" Link to comment https://forums.phpfreaks.com/topic/5078-sorting/#findComment-18079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.