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 |
|
kkmurthy
Starting Member
41 Posts |
Posted - 2009-05-20 : 09:05:54
|
| I have to query the database to pull top ten values. When I use select Top 10 it only pulls Top 10 rows and not Top Ten values.Here is the data I have:27 PASSWORD23 OUTLOOK20 WINXP17 NET_ACCESS15 HOMELESS15 VPN11 BLACKBERRY8 NET_ACCOUNT7 Network Printer6 SPYWARE6 PASSWORD RESETS6 SW_APP_INSTALL6 NTWK_WIRELESSIn the above situation I want to pull all the thirteen rows > Actually they represent top ten values:Help Please. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-20 : 09:10:29
|
[code]SELECT *FROM( SELECT *, rank = dense_rank()OVER (ORDER BY value DESC) FROM data) dWHERE rank <= 10[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
keyursoni85
Posting Yak Master
233 Posts |
Posted - 2009-05-20 : 09:18:32
|
| DECLARE @KSam TABLE (iden int identity, ID INT, Name VARCHAR(9))INSERT @KSamSELECT 3, 'Car' UNION ALLSELECT 1, 'Lion' UNION ALLSELECT 1, 'Rat' UNION ALLSELECT 1, 'Mouse' UNION ALLSELECT 2, 'Apple' UNION ALLSELECT 2, 'Orange'Select * from ( Select (Select Count(*) from @KSam Where ID = Z.ID and iden <= Z.iden) as Item, ID, namefrom @KSam Z) M order by name desc |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-20 : 13:56:15
|
| [code]SELECT TOP 10 WITH TIES *FROM YourTableORDER BY field1 DESC[/code] |
 |
|
|
|
|
|
|
|