Hãy thử cái này:
SELECT DISTINCT fb1.name, fb1.surname FROM favoriteBeer fb1
JOIN stock s ON fb1.beerName = s.beerName
GROUP BY fb1.name, fb1.surname, s.restaurant
HAVING COUNT(*) = (
SELECT COUNT(*) FROM favoriteBeer fb2
WHERE fb1.name = fb2.name AND fb1.surname = fb2.surname
)
Đầu ra:
| NAME | SURNAME |
|-------------|-----------|
| Bucher | Rolf |
| Mastroyanni | Pepe |
| Meier | Hans |
| Meier | Hanspeter |
| Meier | Hansruedi |
| Müller | Heinrich |
| Peters | Peter |
| Zarro | Darween |
Fiddle tại đây .