nested subselects with exists

  • Thread starter Thread starter Jesper F
  • Start date Start date
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.
 
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
 
Back
Top