sql >> Databasteknik >  >> RDS >> Mysql

MySQL Relational Division

Prova detta:

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
)

Utdata:

|        NAME |   SURNAME |
|-------------|-----------|
|      Bucher |      Rolf |
| Mastroyanni |      Pepe |
|       Meier |      Hans |
|       Meier | Hanspeter |
|       Meier | Hansruedi |
|      Müller |  Heinrich |
|      Peters |     Peter |
|       Zarro |   Darween |

Fiol här .




  1. Infoga binär data i MySQL (utan PreparedStatements)

  2. Säkerhet på radnivå fungerar inte för bordsägare

  3. mysql_escape_string hela postarrayen?

  4. SQL Left Join