There are 2 tables, one called drinkers with a column of names, another called frequents which has 2 columns, drinker and bars (that they frequent).
I have a query that answers this statement:
Drinkers who frequent all bars
or wordred differently:
Drinkers such that there aren’t any bars that they don’t frequent
Here is the resulting query:
SELECT d.name
FROM drinkers d
WHERE NOT EXISTS (
SELECT b.name
FROM bars b
WHERE NOT EXISTS (
SELECT *
FROM frequents f
WHERE f.drinker = d.name
AND f.bar = b.name
)
)
I am having the hardest time following the logic when two NOT EXISTS
are used.
How do I understand these types of queries?