June 17, 2003 08:17 PM

A Different Setup

Think differently about set relationships and member properties
Rating: (0)
SQL Server Magazine
InstantDoc ID #38812
Last month, in "Set Members and Relationships" (InstantDoc ID 38515), I presented a group of problems that dealt with identifying sets that have certain relationships with other sets. I mentioned that in relational algebra, the problems I discussed involve relational division. Using a common Orders-OrderDetails scenario, I showed how to find existing orders that had the same products as a new order entered into the system and other variations of the problem. I use these same scenarios again in this article's examples.

You...

...This article is for paid Professional Members only.

Already a Professional Member? Please log in now:

NOT A PROFESSIONAL MEMBER? YOU CHOOSE:

Professional Membership

Monthly

Annual

VIP Membership

Monthly

Annual

Add a Comment

I am having trouble understanding the logic of the solution for p equal to 0(task#2). Can anyone explain to me why the following code works:
SELECT orderid
FROM Orders AS O
WHERE NOT EXISTS
(SELECT * FROM #ProdList AS PL
WHERE NOT EXISTS
(SELECT * FROM OrderDetails AS OD
WHERE OD.orderid = O.orderid AND OD.productid = PL.productid))
AND NOT EXISTS
(SELECT * FROM OrderDetails AS OD
WHERE OD.orderid = O.orderid
AND NOT EXISTS
(SELECT * FROM #ProdList AS PL
WHERE PL.productid = OD.productid))

but this code does not:
SELECT orderid
FROM Orders AS O
WHERE NOT EXISTS
(SELECT * FROM #ProdList AS PL
WHERE NOT EXISTS
(SELECT * FROM OrderDetails AS OD
WHERE OD.orderid = O.orderid AND OD.productid = PL.productid))
AND NOT EXISTS
(SELECT * FROM OrderDetails AS OD
WHERE NOT EXISTS
(SELECT * FROM #ProdList AS PL
WHERE OD.orderid = O.orderid
AND PL.productid = OD.productid))

???

Steve Gordon 10/4/2003 3:42:58 PM


You must log on before posting a comment.

Are you a new visitor? Register Here
GOOGLE LINKS
SPONSORED LINKS
FEATURED LINKS