Query

W

Warrio

Is it possible to create a query that selects from a table the group of
records that are equal to another group?
to make it clearer, the table looks like:

ID Name
1 John
1 Carl
1 Catherine
2 John
2 Carl
3 John
3 Mark
3 Carl


How can I ask to get the ID of the group of records that contain ONLY, i.e..
the names "John, "Mark", "Carl"? so the result would be 3
and I can't use SELECT ID FROM myTable WHERE NAME IN ("John, "Mark",
"Carl"), because the result will show all the IDs where one of the names
appear..

Thanks for any suggestion
 
D

Dan Artuso

HI,
This may send you in the right direction. I know I've used something similiar
a while back.
SELECT id
FROM tblGroups
Where fName = 'john' OR fName = 'mark' OR fName = 'carl'
Group By Id
HAVING Count(fName) = 3;

Thing is, you have to change the Having number to match the number of names or it
doesn't work. For instance, if you just want to find the group that has john and mark,
you change the the number to 2. You could do this dynamically in code.

Someone might have a better way to do this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top