0

I have 2 tables like this:

Table1

id | name
------------------
1  | David
2  | Lucas
3  | Antonio

Table2

id | name
------------------
1  | Sergio
2  | Sergio
3  | Lucas

I want to select data to group duplicate records and return this:

name
------------------
David
Lucas
Antonio
Sergio

So I tried with this query

SELECT name FROM Table1 JOIN Table2 GROUP BY name

But nothing is returned.

2 Answers2

5

You need UNION instead of JOIN :

SELECT name
FROM table1
UNION 
SELECT name
FROM table2;

JOIN is used for matching rows and produce subsequent columns from joined tables while union will combine all rows from two or more tables.

Yogesh Sharma
  • 49,870
  • 5
  • 26
  • 52
1

use union

 select name fron table1
union
select name from table2
Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63