Re: Many-Many relation, matching all

2006-11-28 Thread ddevaudreuil
BY AID HAVING count(distinct BID) =2 Donna Peter Brawley <[EMAIL PROTECTED]> 11/28/2006 10:53 AM Please respond to [EMAIL PROTECTED] To James Northcott / Chief Systems <[EMAIL PROTECTED]>, "mysql@lists.mysql.com" cc Subject Re: Many-Many relation, matching all

Re: Many-Many relation, matching all

2006-11-28 Thread Peter Brawley
James Northcott / Chief Systems wrote: >SELECT AID >FROM AhasB WHERE BID in (1,2) >GROUP BY AID >HAVING count(BID) =2 Not quite, since that will catch aid's with two bid=1 rows or bid=2 rows: SELECT * FROM t; +--+--+ | i| j| +--+--+ |1 |4 | |1 |5 | |3

Re: Many-Many relation, matching all

2006-11-28 Thread James Northcott / Chief Systems
Peter Brawley wrote: >I want to find all A's such that >they have exactly B's 1 and 2 >SELECT A.ID, group_concat(BID ORDER BY BID) as Bs >FROM A INNER JOIN AhasB ON A.ID=AID >GROUP BY A.ID >HAVING Bs='1,2' Why the join? Doesn't your ahasb bridge table already incorporate the join logic? If your

Re: Many-Many relation, matching all

2006-11-28 Thread ddevaudreuil
I think this will work: SELECT AID FROM AhasB WHERE BID in (1,2) GROUP BY AID HAVING count(BID) =2 Donna James Northcott / Chief Systems <[EMAIL PROTECTED]> 11/27/2006 04:35 PM To mysql@lists.mysql.com cc Subject Many-Many relation, matching all Hello, I'm having a conceptual iss

Re: Many-Many relation, matching all

2006-11-27 Thread Peter Brawley
>I want to find all A's such that >they have exactly B's 1 and 2 >SELECT A.ID, group_concat(BID ORDER BY BID) as Bs >FROM A INNER JOIN AhasB ON A.ID=AID >GROUP BY A.ID >HAVING Bs='1,2' Why the join? Doesn't your ahasb bridge table already incorporate the join logic? If your requirement is to ret