Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
pmotewar
Yak Posting Veteran
62 Posts |
Posted - 2009-05-11 : 08:46:42
|
| [code]ID VALUE1 101 111 121 131 141 151 161 171 181 191 202 212 222 232 242 252 262 272 282 292 302 312 322 333 343 353 363 373 383 393 403 413 423 433 444 454 464 474 484 494 504 514 524 534 544 55 hi, above is my table data ( test data) and i want top 5 from each id in single query how can i write the query ?any help appriciated.[/code]Pankaj |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-05-11 : 08:49:09
|
| http://sqlblogcasts.com/blogs/madhivanan/archive/2008/09/12/return-top-n-rows.aspxMadhivananFailing to plan is Planning to fail |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-05-11 : 08:58:31
|
| select id, valueid from (select row_number() over(partition by id order by id) as rid ,* from urtablename )s where rid <=5 |
 |
|
|
pmotewar
Yak Posting Veteran
62 Posts |
Posted - 2009-05-11 : 09:24:42
|
quote: Originally posted by bklr select id, valueid from (select row_number() over(partition by id order by id) as rid ,* from urtablename )s where rid <=5
Thank you very much it's working finethanks again Pankaj |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-05-11 : 09:32:47
|
quote: Originally posted by pmotewar
quote: Originally posted by bklr select id, valueid from (select row_number() over(partition by id order by id) as rid ,* from urtablename )s where rid <=5
Thank you very much it's working finethanks again Pankaj
ur welcome |
 |
|
|
|
|
|