|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
select top 3
I have a table that holds comment records. The columns are :
user_id, comment, date How can I write a select statement that returns the 3 most recent comment records for each user, all in one recordset. thanks for any help. |
|
#2
|
||||
|
||||
|
SELECT TOP 3 *
FROM table ORDER BY date DESC
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
|||
|
|||
|
scorp,
this returns the top 3 across all users. i need to get the top 3 for each user. i've done it with a cursor, but i'd like to find a more efficient way. cj |
|
#4
|
|||
|
|||
|
Code:
select * from t as q where date in ( SELECT TOP 3 date FROM t where t.user_id = q.user_id ORDER BY date DESC) |
|
#5
|
|||
|
|||
|
Thanks swampBoogie, it worked.
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > select top 3 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|