Home » questions » php-mysql, order the results of a query in a confusing way.?

php-mysql, order the results of a query in a confusing way.?

2006-08-14 14:59:31, Category: Programming & Design
There is a database with 10 records and 2 fields. Ex: 0,- 1,- 2,- 3,- 4,1, 5,2 6,3 7,4 8,- 9,- etc. I want all the records selected en sorted like: 1 2 3 4 - - - - - - etc the integer values on the top in ASC end the null's underneath ex. delect variable1, variable2 from database ....... I want the order by code to acomplish such an order How do i do it?

Answers

  1. clievers

    On 2006-08-14 15:21:25


    Sorry, I don't know how you could pull this off strictly with order by's. I don't know if it's possible. Are Union's an option for you? ( SELECT f1, f2 FROM t WHERE f2 IS NOT NULL ORDER BY f2, f1 ) UNION ( SELECT f1, f2 FROM t WHERE f2 IS NULL ORDER BY f1 ) This will bring back the non-null's first, ordered; then the null records