How to get unique values when using a UNION mysql query
Posted
by Roland
on Stack Overflow
See other posts from Stack Overflow
or by Roland
Published on 2010-06-17T13:00:43Z
Indexed on
2010/06/17
13:03 UTC
Read the original article
Hit count: 235
mysql
I have 2 sql queries that return results, both contain a contract number, now I want to get the unique values of contract numbers
HEre's the query
(SELECT contractno, dsignoff FROM campaigns WHERE clientid = 20010490 AND contractno != '' GROUP BY contractno,dsignoff) UNION (SELECT id AS contractno,signoffdate AS dsignoff FROM contract_details WHERE clientid = 20010490)
So for example, if the first query before the union returns two results with contract no 10, and the sql query after the union also returns 10, then we have 3 rows in total, however because contractno of all three rows is 10, I need to have only one row returned, Is this possible?
© Stack Overflow or respective owner