Page 1 of 1

ORDER BY column ASC but...

Posted: Wed Jan 30, 2008 1:41 pm
by alex.barylski
Here is my query:

[sql]SELECT * FROM $table ORDER BY $column $direction LIMIT $offset, $count[/sql]

My $table has a field in it called time which is how the table above is usually sorted. Everything works, except that I am trying to order the oldest records first, basically implementing a FIFO (first in, first out) stack. However easy this, I *also* need to have any records with a timestamp of ZERO to be pushed to the bottom as that indicates lowest priority and shouldn't be pushed to the top of the stack even though technically, they are the oldest records...

Make sense? Can it be done while still showing all the records? Do I have to use sub-queries - hopefully there is another technique.

Re: ORDER BY column ASC but...

Posted: Wed Jan 30, 2008 2:32 pm
by Kieran Huggins
what if the zeroed timestamps are NULL instead? I seem to recall them coming first for some reason in that case.

Re: ORDER BY column ASC but...

Posted: Wed Jan 30, 2008 4:10 pm
by alex.barylski
Kieran Huggins wrote:what if the zeroed timestamps are NULL instead? I seem to recall them coming first for some reason in that case.
Hmmm...maybe I could try that...although I need records with a NULL timestamp to come *last* not first... :?

Re: ORDER BY column ASC but...

Posted: Wed Jan 30, 2008 4:23 pm
by Kieran Huggins
Sorry, that IS what I meant. I think NULL sorts high, not low.

Re: ORDER BY column ASC but...

Posted: Wed Jan 30, 2008 4:36 pm
by alex.barylski
Kieran Huggins wrote:Sorry, that IS what I meant. I think NULL sorts high, not low.
Only one way to find out I guess. Lemme know how it goes, eh? :D :P

Just kidding... :lol: