This is more out of curiosity/scientific interest than based on a real problem.
A programming language is supposed to be a tool and tools are made to make working easier. So why is it that you can find all entries in a one table by simply doing SELECT * FROM foo WHERE bar=42;
but as soon as there are multiple tables involved, there is no easy/intuitive way to say "find all tuples meeting this criteria"?
The example is about components which are shipped to different projects in different cities. Primary keys in bold.
component(**CNR**,Cname,Color,Weight,City)
project(**PNR**,Pname,City)
scp(**SNR**,**CNR**,**PNR**,Quantity)
The task is to write a query to find all components that are/were shipped to all projects in one specific city.
The given solution:
SELECT CNR
FROM components
WHERE NOT EXISTS (
SELECT 1
FROM project
WHERE project.city = 'Foobar Town'
AND NOT EXISTS (
SELECT 1
FROM scp
WHERE scp.PNR = projekt.PNR
AND scp.CNR = components.CNR ));
It is correct, makes sense and even works. But it is not intuitive--a straightforward statement of "get me this". Why?
The example and all the material in our course is based on SQL92.