UltraSmooth
Programmer
I need to make a join between 3 tables, where the 3rd table is dependent on the join of the first two. Here's an example to elaborate,
Table A
A.col1
A.col2
...
A.colN
Table B
B.col1
B.col2
B.col3
...
B.colN
Table C
C.col1
C.col2
C.col3
...
C.colN
I need col1 from table A, col2 from table B and col3 from table C.
Table A and B are joined on col1. Table C is related to table A on col1 and table C is related to table B on col2. What's the most efficient way to write this query? So far I have something that looks like this (but is not working quite right):
SELECT A.col1,B.col2,C.col3
FROM A
JOIN B
ON A.col1=B.col1
JOIN C
ON C.col1=A.col1
AND C.col2=B.col2
When I add in the join with table C my result set returns more records than it should. Of course my real world example has a lot more columns but basically this is what I'm doing. Table C requires the join on tables A and B to get the columns it needs to join.
Am I on the right track? Is it not the proper way to make this join?
Thanks for any help!
Table A
A.col1
A.col2
...
A.colN
Table B
B.col1
B.col2
B.col3
...
B.colN
Table C
C.col1
C.col2
C.col3
...
C.colN
I need col1 from table A, col2 from table B and col3 from table C.
Table A and B are joined on col1. Table C is related to table A on col1 and table C is related to table B on col2. What's the most efficient way to write this query? So far I have something that looks like this (but is not working quite right):
SELECT A.col1,B.col2,C.col3
FROM A
JOIN B
ON A.col1=B.col1
JOIN C
ON C.col1=A.col1
AND C.col2=B.col2
When I add in the join with table C my result set returns more records than it should. Of course my real world example has a lot more columns but basically this is what I'm doing. Table C requires the join on tables A and B to get the columns it needs to join.
Am I on the right track? Is it not the proper way to make this join?
Thanks for any help!