Hello.
I have a script that I am pulling data from a MySQL db.
I would like to do a double-ORDER BY.
Ok, here is a brief-overview.
I have:
DateTime (unix)
Title
Description
Rating (0-5)
Status (active, in progress, completed, etc)
At this point, I us: ORDER BY DateTime
However, I would -like to- do:
ORDER BY Rating WHERE Rating = (0 first, 5 last) AND ORDER BY Status WHERE Status = (completed last)
So, I would like to FIRST display all entries where the ‘rating’ is higher and ‘status’ != completed
THEN display all the other entries where ‘status’ != completed and sort these by DateTime
THEN display all the ‘status’ == completed
Is this something MySQL is capable of?
If so, how in the world would I go about writting my SQL statmenet for this??
Thanks!!
I use
order by table.field1 asc, table.field2 DESC
No problemo
Greets,
Peanuts
Originally posted by AbelaJohnB
[B]Hello.
I have a script that I am pulling data from a MySQL db.
I would like to do a double-ORDER BY.
Ok, here is a brief-overview.
I have:
DateTime (unix)
Title
Description
Rating (0-5)
Status (active, in progress, completed, etc)
At this point, I us: ORDER BY DateTime
However, I would -like to- do:
ORDER BY Rating WHERE Rating = (0 first, 5 last) AND ORDER BY Status WHERE Status = (completed last)
So, I would like to FIRST display all entries where the ‘rating’ is higher and ‘status’ != completed
THEN display all the other entries where ‘status’ != completed and sort these by DateTime
THEN display all the ‘status’ == completed
Thanks!! [/B]
Try:
GROUP BY Status ORDER BY RATING DESC, DATETIME ASC
That should give you something similar to the results you are looking for.
Take care,
Brian
Originally posted by AbelaJohnB
So, I would like to FIRST display all entries where the ‘rating’ is higher and ‘status’ != completed
what does “‘rating’ is higher” mean? i can’t say too much without knowing what “higher” means. but, yeah, i’m sure whatever you want can be done. maybe you can just tell me what you want in a little more detail? 
this would sort the ones that have status==completed last, and then by rating:
ORDER BY status='completed', rating
if that’s not what you want (and it’s prob not :)) give me an EXACT example of how you want rows to appear and it should be pretty easy.