Jump to content


Photo

Sorting


  • Please log in to reply
2 replies to this topic

#1 mcmuney

mcmuney
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 16 March 2006 - 01:10 AM

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???

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 March 2006 - 01:28 AM

[!--quoteo(post=355539:date=Mar 16 2006, 01:10 AM:name=mcmuney)--][div class=\'quotetop\']QUOTE(mcmuney @ Mar 16 2006, 01:10 AM) View Post[/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
SELECT * FROM t1 ORDER BY key_part1 DESC, key_part2 ASC;


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 


[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
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 16 March 2006 - 07:09 PM

It's just "ORDER BY x ASC, y DESC"




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users