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.

 All Forums
 Development Tools
 ASP.NET
 problem with TOP n WITH TIES

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-04-22 : 07:30:58
yousef writes "i have this data
id point
---------------------------------------------
a 100
b 100
c 90
d 90
e 80
f 70
g 60
. .
. .
. .
and my out put is

id point
---------------------------------------------
a 100
b 100
c 90
d 90
e 80

i use this code :

select top 3 with ties id,point
from tbPoint
order by point desc

but i get
id point
---------------------------------------------
a 100
b 100
c 90
can someone help me?"

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2003-04-22 : 09:28:34
Yousef:
What this query returns is logically correct, it is returning the top 3 combinations of id and point. You might want to use a sub-query to return the top three points like this:

SELECT id, point FROM tableName WHERE point IN
(SELECT DISTINCT TOP 3 point from tableName order by point DESC)

OS

Go to Top of Page
   

- Advertisement -