Mysql
 sql >> Database >  >> RDS >> Mysql

SQL:NON IN alternativa per selezionare le righe in base ai valori di *diverse* righe?

In questo modo:

SELECT a.name, a.team
FROM bowlers a
LEFT OUTER JOIN bowlers b ON a.name = b.name AND b.team = 'pin pals'
WHERE a.team = 'The homer team'
AND b.name IS NULL;

Puoi anche farlo in questo modo:

SELECT a.name, a.team
FROM bowlers a
WHERE a.team = 'The homer team'
AND NOT EXISTS (SELECT * FROM bowlers b
    WHERE b.team = 'pin pals'
    AND a.name = b.name
    );

A proposito, questo si chiama "Adesione antisemita di sinistra".