Forum Moderators: open

Message Too Old, No Replies

Priority ordering with different columns

         

kuper20

11:50 pm on Jun 24, 2008 (gmt 0)

10+ Year Member



Hi, so I'm thinking about putting in a way to priority order some of my columns in a table that's outputted on my website. I'd like a form that has say three inputs for column names. After it's submitted, I'd want to order by the first one, and if that's the same then order by the second one, and if both of those are the same then order by the third one. ORDER BY can only order by one column. Is there an easy way to do this kind of priority ordering?

Thanks

physics

12:04 am on Jun 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




For example, to sort by type of animal in ascending order, then by birth date within animal type in descending order (youngest animals first), use the following query:

mysql> SELECT name, species, birth FROM pet
-> ORDER BY species, birth DESC;


[dev.mysql.com...]

LifeinAsia

12:08 am on Jun 25, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



ORDER BY can only order by one column.

ORDER BY certainly isn't limited to 1 column- we have numerous queriries sorting on 2, 3, 4, 5, or even more columns.

kuper20

12:19 am on Jun 25, 2008 (gmt 0)

10+ Year Member



oh so you just separate them by commas, i see