Reputation: 99
I have three tables with the following relation.
t1 has program_id
t2 has program_id and product_name
t3 has product_name and price
t1
order_id|product_id| program_id
1 | AA| 100
2 | BB| 110
3 | CC| 500
4 | DD| 550
t2
name |program_id| name
mike | 100| 1bx
john | 110| 2bx
bob | 500| 3bx
clara | 550| 3bx
jane | 112| 55x
t3
admin_id|product_name|revenue
z1 | 1bx| 100
z2 | 2bx| 110
z3 | 3bx| 500
z4 | 4bx| 550
My purpose here is to JOIN the first two tables and after that JOIN the result of the first JOIN with the third table. In the end it should look something like:
t4
program_id|product_name|revenue
z1 | 1bx| 100
z2 | 2bx| 110
z3 | 3bx| 500
z4 | 4bx| 550
where t3 would give me the price for each program_id and product_name. How could I efficiently join the third table with the result of the first Join?
Upvotes: 0
Views: 95
Reputation: 1269463
This just sounds like two JOIN
s to me:
select program_id, product_name, revenue as price
from table1 t1 join
table2 t2
using (program_id) join
table3 t3
using (product_name);
Upvotes: 1