Get latest sql rows based on latest date and per user
Posted
by
Umair
on Stack Overflow
See other posts from Stack Overflow
or by Umair
Published on 2013-11-10T21:32:39Z
Indexed on
2013/11/10
21:54 UTC
Read the original article
Hit count: 291
sql
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.
© Stack Overflow or respective owner