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

Ottieni una voce specifica in caso di voce duplicata

SOLUZIONE AGGIORNATA:

SELECT UserId, First name, Last name, IsRequired, IsDeleted FROM table WHERE UserId IN (SELECT UserId FROM users GROUP BY UserId HAVING count(distinct(IsRequired)) > 1) and IsRequired = 'true'
UNION
SELECT UserId, First name, Last name, IsRequired, IsDeleted FROM table WHERE UserId IN (SELECT UserId FROM users GROUP BY UserId HAVING count(IsRequired) = 1)

Consulta http://sqlfiddle.com/#!3/d178f/1/0

Hanno riprodotto la stessa identica struttura del database.