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

query sql per selezionare record con lo stesso ID ma valore diverso in due colonne

SELECT youtable.*
FROM yourtable
WHERE articleid IN (SELECT articleid
                    FROM yourtable
                    WHERE (fieldsid, value) IN ((1,1),(2,1))
                    GROUP BY articleid
                    HAVING COUNT(*)=2)

modifica:se ti serve solo il primo record:

SELECT youtable.*
FROM yourtable
WHERE id IN (SELECT MIN(id)
             FROM yourtable
             WHERE (fieldsid, value) IN ((1,1),(2,1))
             GROUP BY articleid
             HAVING COUNT(*)=2)