I have 2 tables in MYSQL that will be joined by a foreign key. Each table has its own date field. What I would like to do is combine these two date fields together and then order by the combined information. I understand that you can order by multiple fields but I don’t think that combines them.
Example
Join by tickets.ticket_id = ticket_history.ticket_id
Table 1
ticket_date
Table 2
ticket_history_date
Goal combine the two date fields and then order the rows by the combined dates
Let’s assume that you want the latest of the two dates, you can do something like this
If you wanted the oldest date you could use LEAST rather than GREATEST. If one of the dates might be NULL then you might want to look into COALESCE