Thread: SQL subsets
View Single Post
  #7  
Old May 14th, 2010, 05:54 PM posted to microsoft.public.access.queries
Bob Barrows
external usenet poster
 
Posts: 475
Default SQL subsets

It never hurts to show us a few rows of sample data in tabular form, and
follow that with the results you wish to obtain, again in tabular form.

StacyC wrote:
OK, I tried that and did not get the results I needed. I'm probably
not articulating the goal/objective of my query precisely enough.
Thanks,
Stacy

Bob Barrows wrote:
I'm sorry, but I'm not looking over your shoulder at your puter
screen :-)

All I know so far is you have a table called tblPermitItems. What are
the relevant fields in this table? Does this table maintain the link
between permitees and items? Hmm ... does the table have two fields?
PermiteeID and ItemID? And does it contain a list of Permitees and
the items they are allowed to use? If so, and you know the ItemIDs of
interest (say these IDs are 1,2 and 3 per your initial post), and
let's also assume you are interested only in those permitted to own
all three of those items (excluding those that have been granted use
for one or two of them) then:

SELECT DISTINCT PermiteeID
FROM tblPermitItems
WHERE ItemID = 3
AND PermiteeID IN (SELECT PermiteeID FROM tblPermitItems WHERE
ItemID=1) AND PermiteeID IN (SELECT PermiteeID FROM tblPermitItems
WHERE ItemID=2) AND NOT PermiteeID IN (SELECT PermiteeID FROM
tblPermitItems WHERE ItemID NOT IN (1,2,3))

If you want all of the permitees restricted to any of the 1-3 items,
then

SELECT DISTINCT PermiteeID
FROM tblPermitItems
WHERE ItemID IN (1,2,3)
AND NOT PermiteeID IN (SELECT PermiteeID FROM tblPermitItems WHERE
ItemID NOT IN (1,2,3))

Beginnng from the bottom:
No, there is no field that identifies restricted permittes

[quoted text clipped - 20 lines]
Permitee master table containing a field that identifies the
restricted Permitees?


--
HTH,
Bob Barrows