I have a generic function (php) that retrieves multiple records of a table by matching a column value and orders them by a datetime field. In some instances the datetime is the same for multiple records, inserted at nearly the same time, and on these tables there is another column that is a record number, an automatically incrementing number. I would like to check if the table has this record number column present, and if so, sort by it. Otherwise if the record number column does not exist in the table I want to sort by the datetime field. I could write a separate function, sorting for record numbers, but prefer this to be handled by a single function using a mysql solution.
I just want to know if this can be done?
Using IF, Exist, or orderby?