Order by time with NULL last [Solved]

I’m selecting things from a table in order of time.

"SELECT id, title, time, locat, sched FROM programme WHERE status != 'f' AND date = :day ORDER BY time, id"

Some entries don’t have their time set, so the time column has a NULL value.
As it is the NULL entries come before the ones with times.
How can I make them come after?

OK I found it on SO:-

"SELECT id, title, time, locat, sched FROM programme WHERE status != 'f' AND date = :day
ORDER BY CASE WHEN time IS NULL THEN 1 ELSE 0 END, time, id"

Note to self: Google before posting.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.