tags:

views:

85

answers:

4

Hi, 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

+3  A: 

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?

Donut
+5  A: 

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

Chris McCall
+1. Your telepathy skills are equal to mine, but you type faster :-)
ChssPly76
It's also called a cross-join.
AviD
but doesn't "Cartesian Product" sound more computerish?
Chris McCall
+1  A: 

It is CROSS JOIN.

shahkalpesh
A: 

Based on your output, your query is something like

SELECT * FROM Table2, Table1

This is called a CROSS JOIN and this is the normal behavior that for each row in table2, the values from table1 will be appended.

What you seem to want is a UNION

SELECT * FROM Table1
UNION
SELECT * FROM Table2
Pierre-Alain Vigeant