Get latest sql rows based on latest date and per user
- by Umair
I have the following table:
RowId, UserId, Date
1, 1, 1/1/01
2, 1, 2/1/01
3, 2, 5/1/01
4, 1, 3/1/01
5, 2, 9/1/01
I want to get the latest records based on date and per UserId but as a part of the following query (due to a reason I cannot change this query as this is auto generated by a tool but I can write pass any thing starting with AND...):
SELECT RowId, UserId, Date
FROM MyTable
WHERE 1 = 1
AND (
// everything which needs to be done goes here . . .
)
I have tried similar query, but get an error:
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.