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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL Top Ten Command

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-12-14 : 08:12:46
Dylan Nash writes "Hi,

I hope you can help,

I want to get the top ten out of sql but using group by.

i tried:

Select top 10 scores,person,age,sex
from table1
group by person.

So i should get back 20 rows, 10 scores for each person (assuming there was 2)
But this gives an error message.

i also want to order them by scores so i get the top ten in score order, by each person

Select top 10 scores,person,age,sexy
from table1
order by scores
group by person

I am using SQL server 2K, and win2k

is this even possible in MSSQL?

Thanks in advance"

B0g
Starting Member

19 Posts

Posted - 2004-12-14 : 08:35:23
TOP 10 will return first 10 rows of the table.

I think that this query shoul help you:

SELECT scores,person,age,sex
FROM Table1 T1
WHERE Scores IN (SELECT TOP 10 Scores
FROM Table1
WHERE person = t1.person
ORDER BY scores)
Go to Top of Page
   

- Advertisement -