Thursday 15 August 2013

sql - MySQL Order by multiple column combined (not order by field1 asc, field2 asc) -


It looks like a common question, but it is different.

I have an ID with ID and minus all 3 Field 3 timestamp field (just) started, and they are filled with values. Examples of lines are:

  id time 1 2 time3 1 +125 9 625661 +125 9 643563 Null Null 2 ​​+125 9 621 231 null 3 +125 9 62 588 9 null +125 9 644 511 4 null +125 9 621 231 null 5 null null +125 9 644 511 6 null +125 9 621231 null 7 +125 9 62 588 9 null null   

a list of IDs recent timestamp (ignore if time is 1 time 2 or 3) . Time 1 desc, while 2 desc, time3 by command desc me as a wrong list gives you all the time 1 field, and the other, etc ...

required, This is the first type of result ID.

Can this be done in a single query in MySQL? Thank you

  SELECT * most by MyTable order (COALESCE (1, 0) , COALESCE (time 2, 0), coal (time 3, 0)) DESC  

No comments:

Post a Comment