Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

consulta sql para selecionar registro com o mesmo id, mas valor diferente em duas colunas

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)

edit:se você precisar apenas do primeiro registro:
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)