我有3张桌子
表1
table1_ID name address
1 name1 bangalore
2 name2 chennai
3 name3 mumbai
表2
table2_ID age hobbies
1 20 reading
2 25 cricket
3 22 indoor games
table3_mapping
table1_ID table2_ID
1 2
2 2
3 1
现在,我应该如何根据table1_ID获取table2中的数据,table1_ID-> table2_ID ......如果我选择name1,那么我应该得到该名称的年龄和爱好。希望你能理解这个问题。谢谢,
答案 0 :(得分:0)
简单使用join
select t1.*,t2.* from t3
join t1 on t1.ID=t3.table1_ID
join t2 on t2.ID=t3.table2_ID
答案 1 :(得分:0)
这样的事情:
select t1.*, t2.*
from table1 t1
join table3 t3 on t3.table1_id = t1.table1_id
join table2 t2 on t2.table2_id = t3.table2_id