Take the same relational database tables as before:
RESTAURANT(RT_ID, NAME, TYPE, LOCATION)
PROXIMITY(RT1_ID, RT2_ID, DISTANCE)
USER(U_ID, NAME, EMAIL)
REVIEW(U_ID, RT_ID, RT_DATE, RATING, COMMENT)
Find the names of the reviewers who reviewed all the restaurants in Earlsfield.
But what about SQL? As I wrote of relational division when I started the blog:
one has to implement a “double not exists” query
In this case that means “find the name of any reviewer for whom there is no Earlsfield restaurant not reviewed by that reviewer”:
SELECT NAME
FROM USER
WHERE NOT EXISTS (
SELECT *
FROM RESTAURANT
WHERE LOCATION=’Earlsfield’ AND
NOT EXISTS (
SELECT *
FROM REVIEW
WHERE REVIEW.U_ID = USER.U_ID AND
REVIEW.RT_ID = RESTAURANT.RT_ID))
At least, I hope so! I am finding this all quite heavy going – and have ordered a book – SQL and Relational Theory: How to Write Accurate SQL Code – in the hope that it will help makes things clearer. Any other recommendations gratefully received.
Update: It does work, amazingly enough.
Related Articles
- Relational algebra problem (cartesianproduct.wordpress.com)
- Microsoft Researchers: NoSQL Needs Standardization (pcworld.com)
- NoSQL, NewSQL highly scalable databases (nextbigfuture.com)
4 responses to “Relational division again”
[…] cartesian product Stuff about computing Skip to content HomeAbout ← Relational division again […]
[…] Relational division again (cartesianproduct.wordpress.com) […]
[…] Relational division again (cartesianproduct.wordpress.com) […]
[…] Relational division again (cartesianproduct.wordpress.com) […]