Forum Moderators: open

Message Too Old, No Replies

Need extract following information

         

orion_rus

6:29 am on Apr 20, 2006 (gmt 0)

10+ Year Member



I have 2 tables:
Persons
id = personid
Contacts
id = contactid
personid -> Persons:personid

I need to extract information about persons who have exactly 2 contacts.
How it possible?
Thanks in advance

coopster

7:28 pm on Apr 20, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Use a GROUP BY clause with a HAVING clause:
SELECT 
Persons.personid
FROM Persons
INNER JOIN Contacts ON Persons.personid = Contacts.personid
GROUP BY Persons.personid
HAVING COUNT(Contacts.personid) = 2
;