select * from P,J,SPJ where SPJ.J#=J.J# and SPJ.P#=P.P#
select s# from S where not exists (select * from SPJ spj1,SPJ spj2 where spj1.S#=S.S# and spj2.S#=S.S# and not exists ( select * from SPJ spj3 where SPJ3.S#=S.S# and SPJ3.P#=spj1.P# and SPJ3.J#=spj2.J# ) )
select J# from SPJ where S#='s3'
select P# from SPJ where S#='s3'
select spj1.P#,spj2.J# from SPJ spj1,SPJ spj2 where spj1.S#='s3' and spj2.S#='s3'
select distinct J# from SPJ where P# in (select P# from SPJ where S#='s4')
select distinct spj1.J# from SPJ spj1,SPJ spj2 where spj2.S#='s4' and spj1.P#=spj2.P#
select P# from SPJ where S#='s1'
Baza Northwind
1) Znaleźć CustomerID takich klientów co kupują wszystko
select CustomerID from Customers where not exists (select * from Products where not exists(
select * from Orders join [Order Details] on [Order Details].OrderID=Orders.OrderID where [Order Details].ProductID=Products.ProductID and Orders.CustomerID=Customers.CustomerID
))
2) Znaleźć ProductID produktów dostarczanych do wszystkich klientów
select ProductID from Products where not exists (select * from Customers where not exists(
select * from Orders join [Order Details] on [Order Details].OrderID=Orders.OrderID where [Order Details].ProductID=Products.ProductID and Orders.CustomerID=Customers.CustomerID