I need to join 3 tables using an explicit join. There is not a common key across all three tables.
Asked
Active
Viewed 1,188 times
-3
-
do you have a common key for table1 and table2 and a different common key for table2 and table3? – Marco Nov 03 '11 at 17:05
-
What is the problem? That you want to avoid getting duplicate rows because you'll be joining on non-key columns? – Matt Fenwick Nov 03 '11 at 17:08
-
@Marco... Yes. the tables can be linked that way. – Pepper Crist Nov 03 '11 at 17:11
1 Answers
1
If you need to join tables you need a common key for every pair.
So you can try something like this:
SELECT t1.*, t2.*, t3.*
FROM table1 t1 INNER JOIN table2 t2
ON t1.id1 = t2.id1
INNER JOIN table3 t3
ON t2.id2 = t3.id2

Marco
- 56,740
- 14
- 129
- 152
-
@Pepper: so, do you need something like my example? If not, provide more details please... – Marco Nov 03 '11 at 17:13
-
I believe this will work. From my understanding this is postgresql and I am not familiar with it. I've worked with all the other flavors just not this one. Thank you for your help. – Pepper Crist Nov 03 '11 at 17:16
-