hi
I have problem with sql. I dont userstand what should I do.
my problem is
I have table UserLocationHistory
I want those user who have latest date.
I am fired sql like
SELECT DISTINCT userid, datetime
FROM UserLocationHistory
ORDER BY userid, datetime DESC
UserID datetime
801/5/2005
801/4/2005
801/2/2005
1241/3/2005
1241/2/2005
1241/1/2005
1301/3/2005
1861/1/2005
but I wnat this reasult like
UserID datetime
801/5/2005
1241/3/2005
1301/3/2005
1861/1/2005
so please help me out
regards,
bhavik
TRY THIS:-
SELECT userid, max(datetime) as date
FROM UserLocationHistory
Group by userid
ORDER BY userid
Thanks
Hari
SQL Server MVP
"bhavik" <bhavik@.discussions.microsoft.com> wrote in message
news:E157B034-E349-4EA8-B165-3BDC557EBE6F@.microsoft.com...
> hi
> I have problem with sql. I dont userstand what should I do.
> my problem is
> I have table UserLocationHistory
> I want those user who have latest date.
> I am fired sql like
> SELECT DISTINCT userid, datetime
> FROM UserLocationHistory
> ORDER BY userid, datetime DESC
> UserID datetime
> 80 1/5/2005
> 80 1/4/2005
> 80 1/2/2005
> 124 1/3/2005
> 124 1/2/2005
> 124 1/1/2005
> 130 1/3/2005
> 186 1/1/2005
>
> but I wnat this reasult like
> UserID datetime
> 80 1/5/2005
> 124 1/3/2005
> 130 1/3/2005
> 186 1/1/2005
> so please help me out
> regards,
> bhavik
|||thanks Hari Prasad
your are GRATE.
bhavik shah
"Hari Prasad" wrote:
> TRY THIS:-
>
> SELECT userid, max(datetime) as date
> FROM UserLocationHistory
> Group by userid
> ORDER BY userid
> Thanks
> Hari
> SQL Server MVP
>
> "bhavik" <bhavik@.discussions.microsoft.com> wrote in message
> news:E157B034-E349-4EA8-B165-3BDC557EBE6F@.microsoft.com...
>
>
No comments:
Post a Comment