views:

15

answers:

1

I'm creating a PHP script that fetches IDs from a database. The results are sorted by two datetime values, createdon and publishon.

The priority of publishon is higher than createdon; however, publishon may also be NULL. publishon = null => sort by createdon.

Can someone help me sort those rows?

+3  A: 

use

ORDER BY IFNULL(PublishOn, CreadedOn), CreatedOn

Michael Pakhantsov