I am developing a PHP script that brings IDs from the database. The outcomes are sorted by two datetime values, createdon and publishon.

The priority of publishon is greater than createdon however, publishon can also be NULL. publishon = null => sort by createdon.

Can someone assist me to sort individuals rows?

use

ORDER BY IFNULL(PublishOn, CreadedOn), CreatedOn