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

MYSQL UNION DISTINCT

No. Non puoi specificare con quale campo esatto devi distinguere. Funziona solo con l'intera riga.

A causa del tuo problema, rendi la tua query una sottoquery e in quella esterna GROUP BY user_id

SELECT * FROM 
(SELECT a.user_id,a.updatecontents as city,b.country
FROM userprofiletemp AS a
LEFT JOIN userattributes AS b ON a.user_id=b.user_id
WHERE typeofupdate='city')

UNION DISTINCT

(SELECT a.user_id,c.city,c.country
FROM userverify AS a
LEFT JOIN userlogin AS b ON a.user_id=b.user_id
LEFT JOIN userattributes AS c ON a.user_id=c.user_id
WHERE b.active=1 AND a.verifycity=0) x
GROUP BY user_id