I think I might be writing this query incorrectly. Essentially, I want to find the object with the latest timestamp across four possible values (in this example, user_id is 1).
SELECT *, GREATEST(books.updated_at, books.deleted_at, posts.updated_at, posts.deleted_at) FROM books, posts WHERE books.user_id = 1 OR posts.user_id = 1
This will always return a time for
updated_at, but even if the
deleted_at time for one of the objects is the latest, it will not return a
deleted_at time. I know, because running a query for
deleted_at IS NOT NULL returned a later timestamp.
What am I doing wrong here?