nested subselects with exists

J

Jesper F

I've got it working using the exists word in a subselect.
But can I nest another Exists-sentence inside the first
one?

SELECT * FROM tableX WHERE EXISTS (SELECT * FROM tableY
WHERE tableX.itemID = tableY.itemID AND tableY.personID =
1)
I search for items in tableX where the itemIDs are present
in tableY AND the unitID in tableY should be present in
tableZ.
I'll elaborate if this is unclear. Thanks for any input.
 
M

Michel Walsh

Hi,


with joins

SELECT a.*
FROM tableX As a INNER JOIN tableY as b ON a.itemID=b.itemID
WHERE b.personID=1

and


SELECT a.*
FROM (tableX As a INNER JOIN tableY as b ON a.itemID=b.itemID)
INNER JOIN tableZ as c ON a.itemID=c.itemID
WHERE b.personID=1


or, with EXISTS:


SELECT *
FROM tablex
WHERE EXISTS ( SELECT *
FROM tableY
WHERE tableY.itemID=tableX.itemID
AND tableY.PersonID=1)
AND
EXISTS (SELECT *
FROM tableZ
WHERE tableZ.itemID=tableX.itemID)




Hoping it may help,
Vanderghast, Access MVP
 

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