mysql - How can I select the distinct value of two tables? -


i'm not sure it's possible select distinct value of 2 tables columns.

consider table1 like:

╔══════╗ ║ col1 ║ ╠══════╣ ║ aaa  ║ ║ aaa  ║ ║ bbb  ║ ║ bbb  ║ ╚══════╝ 

and table2 like:

╔══════╗ ║ col1 ║ ╠══════╣ ║ aaa  ║ ║ bbb  ║ ║ ccc  ║ ║ ccc  ║ ╚══════╝ 

the output be:

aaa bbb ccc 

obviously like:

select distinct table1.col1 , table2.col1 table1 , table2; 

won't work.

sqlfiddle

a simple union tricks

select col1 table1  union  select col1 table2; 

there no need use distinct keyword union handle duplicates.

fyi if use union all duplicates won't handled anymore, need use distinct.


Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -