Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Join Problem... what is it called?

Tags:

sql

join

I have two tables that are joined. I've included the 'output' of the joined tables. I'm wondering what is this join problem called? There are duplicating rows.

Table 1          Table 2
ID     Name     ID Name
1     Joey         4 Mary
2     Shawn      5 Xavier
3     Mark         6 Gary

The join output is:

ID     Name     ID Name
4     Mary     1 Joey
4     Mary     2 Shawn
4     Mary     3 Mark
5     Xavier   1 Joey
5     Xavier   2 Shawn
5     Xavier   3 Mark
6     Gary     1 Joey
6     Gary     2 Shawn
6     Gary     3 Mark

like image 550
Shawn H Avatar asked Jun 05 '26 22:06

Shawn H


2 Answers

If memory serves, that's called a Cartesian Product.

like image 61
Chris McCall Avatar answered Jun 08 '26 11:06

Chris McCall


I think your problem is that you want to use UNION, not JOIN.

Example:

SELECT * FROM Table1 UNION SELECT * FROM Table2;

Should give you:

ID  Name
1   Joey
2   Shawn
3   Mark
4   Mary
5   Xavier
6   Gary

Is this what you're trying to do?

like image 25
Donut Avatar answered Jun 08 '26 12:06

Donut