Query to return a subset of a set

D

David Wetmore

I have an M2M relation with a link table (tblTagLinks) containing parent keys (PKey) and child keys (CKey).
I want to return the smallest set of PKey values which have links to two different CKey values.

In other words, how do I combine

SELECT tblTagLinks.PKey
FROM tblTagLinks
WHERE tblTagLinks.CKey = 88

and

SELECT tblTagLinks.Pkey
FROM tblTakLinks
WHERE tblTagLinks.CKey = 50

to get only those PKey values where the result is a subset of CKey 88
containing only those records which also have a link containing CKey = 50?

For example, if one set from tblTagLinks contains

12, 88
14, 88
19, 88

and another set contains

11, 50
12, 50
18, 50

I want an SQL statement which will select only 12 for the PKey

I've tried AND and OR combinations, but all I get is either the empty set or a union.
 

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