I’m trying to turn this query into a view:
SELECT t.*
FROM user t
JOIN (SELECT t.UserId,
MAX( t.creationDate ) 'max_date'
FROM user t
GROUP BY t.UserId) x ON x.UserId = t.UserId
AND x.max_date = t.creationDate
But views do not accept subqueries.
What this does is look for the latest, newest record of a user.
I got the idea from this other stackoverflow question
Is there a way to turn this into a query with joins, perhaps?
Create two views
and then just call the second one…
EDIT: hey, based on comment from Quassnoi, and your inclusion of
where t.CreationDate = MaxDatein yr orig sql, I wonder if you want to see all rows for each distinct user, with the max creation date for that user in every row, or, do you want only one row per user, the one row that was created most recently?If the latter is the case, as @Quassnoi suggested in comment, change the second view query as follows