I have two tables:
parameters1
+------+-----+ | cod | des | +------+-----+ | 1 | aaa | | 2 | bbb | | 3 | ccc |
parameters2
+------+-----+ | cod | des | +------+-----+ | 1 | mmm |
I usually JOIN the result set of these two tables with UNION 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 duplication of UNION only to the cod column, so I want to avoid duplicating 1 cod in the result set (when there is an entry with a 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 delete record 1 from table parameters1 ( 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 duplication of a UNION check to just one field or some fields? How?
The solution should work in an environment with several databases (MSSQL, PostgreSQL, MySQL).
source share