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.
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.