how to remove duplicate from UNION Query result?

Viewed 24

I have two tables :

Table1

id | name | tech
-----------------
1  | jose | python
2  | rolf | java
3  | alain| scala

Table2

id | name | tech
-----------------
4  | jose | haskell
5  | rolf | c++
6  | sylvie|js

I want to merge them with a UNION and get the name only from the first table so the result should be like that:

id | name | tech
-----------------
1  | jose | python
2  | rolf | java
3  | alain| scala
4  | sylvie|js
1 Answers

Use a WHERE clause.

select id, name, tech from table1
union all
select id, name, tech from table2 where name not in (select name from table1);
Related