0

Possible Duplicate:
MySQL Orderby a number, Nulls last

I have a table with columns like this.

NULL
NULL
2012-10-12
NULL
2013-10-17
2012-10-17

I want to sort the date fields in asc and the NULL values to go to the last, to get something like this

2012-10-12
2012-10-17
2013-10-17
NULL
NULL
NULL

I did select xyz from table order by xyz.abc asc; which prints the reverse of this.

Also, played around the order_by with case and IF functions, but couldn't get.

Community
  • 1
  • 1
Manjunath Manoharan
  • 4,567
  • 6
  • 28
  • 43

2 Answers2

1

Did you try this?

SELECT `xyz` FROM `your_table`
ORDER BY (`abc` IS NULL),`abc`
inhan
  • 7,394
  • 2
  • 24
  • 35
-1

Try ::

    select xyz from table where abc is not null order by abc asc
    UNION 
    select xyz from table where abc is null
Sashi Kant
  • 13,277
  • 9
  • 44
  • 71