SQL >> Base de Datos >  >> RDS >> Mysql

Encontrar filas sin coincidencia en otra tabla

Hay tres formas clásicas: NOT IN, LEFT JOIN con IS NULL y NOT EXISTS. Todas pueden devolver el mismo resultado.

SELECT s.*
FROM SURVEYS s
WHERE s.userid != 28
  AND NOT EXISTS (
    SELECT NULL
    FROM RESPONSES r
    WHERE r.userid = 28
      AND r.survey_id = s.surveyid
  );