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 2005 Forums
 Transact-SQL (2005)
 Select distinct with a twist

Author  Topic 

mjroojuice
Starting Member

1 Post

Posted - 2009-01-18 : 20:40:44
We have a table that contains a list of questions, and each question is associated with a team

id, question, team.

What we are trying to do, is return ten questions that only correspond to one team. e.g. there are 16 teams, but return 10 questions, with only 1 question per team showing. Making them return randomly is also handy.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-18 : 22:51:04
just use

SELECT id,question,team
FROM
(SELECT ROW_NUMBER() OVER(PARTITION BY team ORDER BY NEWID()) AS Seq,*
FROM Table
)t
WHERE t.Seq=1
Go to Top of Page
   

- Advertisement -