I have a query like this:
SELECT id, user_id FROM orders GROUP BY user_id ORDER BY id DESC
I am trying to get all of the “last” orders users ordered.
The problem with this query is that GROUP BY runs before ORDER BY, so I still get the first order of each user rather than their last.
Is there another way to write this to get the desired result? Do I need to resort to a second query / sub query?
I think you might want this instead: