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.
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
Post a Comment