sql >> Base de Datos >  >> RDS >> Mysql

mysql:eliminar filas con valores repetidos con condición (columnas repetidas)

Deberías estar buscando esto:

Aquí, estamos omitiendo los key record values (date + name) aquellos coinciden en una intersección de key record values (date + name) who played football y key record values (date + name) who did not play football

SELECT 
    p1.*
FROM
    player p1
        LEFT JOIN
    (SELECT 
        pnfb.*
    FROM
        (SELECT 
        date, name
    FROM
        player
    WHERE
        sport <> 'football') pnfb
    JOIN (SELECT 
        date, name
    FROM
        player
    WHERE
        sport = 'football') pfb ON (pnfb.date = pfb.date
        AND pnfb.name = pfb.name)) p2 ON (p1.date = p2.date AND p1.name = p2.name)
WHERE
    p2.date IS NULL;