Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Help Needed 1

Status
Not open for further replies.

JayKusch

MIS
Oct 30, 2001
3,199
US
Have a table w/ Date and UserID. A user could have logged in 0 to X amount of times. Need to pull the latest 1 to 30 records per user order by user, date. Example would look like ...

UserID Date
------- -------
1 1/25/03
1 1/26/03
2 1/1/03
3 2/14/02
3 12/31/02
3 1/03/03
4 1/2/03
10 3/3/03
10 3/6/03



Thanks

J. Kusch
 
You could add date field that's default value is getdate()
then I think something like this will work...

select top 30 * from your_table
order by DateCreated desc, UserId, Date

Josh
 
select * from t q
where dateColumn in
(select top 30 dateColumn
from t
where userId = q.userId
order by dateColumn desc)
order by userId,dateColumn desc

 
Not quite what I need.

All I want to do is pull the 30 most current records, based on the LogInDate of the record, for each user that has logged in at some point in time. Some users may only have 1 record while others may have hundreds.
Thanks

J. Kusch
 
And SwampBoogie is the winner!!! Thanks
Thanks

J. Kusch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top