There is a table with blog posts where there are two fields - publish_time and date_posted , the fields of publish_time can be empty. Question : How can I use a sql query to sort the data so that sorting takes place across the publish_time field, and if the record is empty - by date_posted ?

    2 answers 2

     order by IFNULL(publish_time,date_posted) 

      I also found a solution for this issue, taking into account the fact that sorting is required by two or more fields:

       ORDER BY COALESCE( expr1, expr2, … expr_n )