I have two tables like the following :
parameters1
+------+-----+
| cod | des |
+------+-----+
| 1 | aaa |
| 2 | bbb |
| 3 | ccc |
parameters2
+------+-----+
| cod | des |
+------+-----+
| 1 | mmm |
I usually JOIN the result set of this two tables with an UNION in this way :
SELECT cod, des
FROM parameters1
UNION
SELECT cod, des
FROM parameters2
and i get this result set :
+------+-----+
| cod | des |
+------+-----+
| 1 | aaa |
| 2 | bbb |
| 3 | ccc |
| 1 | mmm |
I want to limit the UNION duplicate checking only to the cod
column, so i want to avoid that the 1 cod get duplicated in the result set (when there is a record with different name and the same cod), i want to get the name from the first table (parameters1) :
+------+-----+
| cod | des |
+------+-----+
| 1 | aaa |
| 2 | bbb |
| 3 | ccc |
UPDATE
If i remove the record 1
from the parameters1 table(DELETE FROM parameters1 WHERE cod = 1
) i should get this result set :
+------+-----+
| cod | des |
+------+-----+
| 1 | mmm | ---> FROM parameters2
| 2 | bbb |
| 3 | ccc |
Is it possible to limit the duplicate checking of a UNION to only one field or some fields ? How ?
The solution should work on a multidatabase environment (MSSQL, PostgreSQL, MySQL).