# Thread: How to Get unique combination of rows

1. Registered User
Join Date
Jun 2004
Posts
2

## Unanswered: How to Get unique combination of rows

Hi,
Following is my table:Bets

BetId GameID

500 108
500 109

501 108
501 109
501 110

502 108
502 109

I want BetId 500 and 502 to be returned as result if i give select
criteria where game id = 108,109.
Pls.Note: It should not return BetId 501 in the result, since it belongs to different combination(108,109,110).
Similarly if i give, select criteria where game id =(108,109,110) it should return
BetId 501.not the 500 and 502..which is different combination..

Hope i clarified my problem..pls help me in this regard.Thanks a lot...

2. Registered User
Join Date
Nov 2003
Location
London
Posts
169
select *
from Bets
where (gameId = 108 OR gameId = 109) AND BetId <> 501

3. Registered User
Join Date
May 2004
Posts
125
You could also try this so the query would met both requirements:

create table tmpTest
(betid int, gameid int
)
insert into tmptest (betid, gameid) values (500, 108)
insert into tmptest (betid, gameid) values (500, 109)
insert into tmptest (betid, gameid) values (501, 108)
insert into tmptest (betid, gameid) values (501, 109)
insert into tmptest (betid, gameid) values (501, 110)
insert into tmptest (betid, gameid) values (502, 108)
insert into tmptest (betid, gameid) values (502, 109)

select betid from tmptest group by betid having sum(gameid) = (108+109)
select betid from tmptest group by betid having sum(gameid) = (108+109+110)

drop table tmpTest

If anything you can use the above as a subqueiry to a record set of all betid and gameid if you want to see them all.

HTH

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•