I have a table called posts where I have two fields called timestamp_added and timestamp_edited.
I want to order by the latest added or edited posts descending.
ORDER BY p.timestamp_added DESC, p.timestamp_edited DESC, does not give me what I need.
I would love something like:
ORDER BY IF p.timestamp_edited > 0 THEN p.timestamp_edited DESC ELSE p.timestamp_added DESC
How do I do this? I have tried to google this, but I have trouble finding what I need.
Is the timestamp_edited NULL when not set?
In that case you could do:
If it’s 0 when not set: