Namburi Akhil Namburi Akhil - 5 months ago 13
MySQL Question

get the table data based on another table id

I have 3 tables


table1_ID name address
1 name1 bangalore
2 name2 chennai
3 name3 mumbai


table2_ID age hobbies
1 20 reading
2 25 cricket
3 22 indoor games


table1_ID table2_ID
1 2
2 2
3 1

now, how should I get the data from table2 based on table1_ID where,table1_ID->table2_ID......if I select name1 then i should get age and hobbies of that name. Hope you understood the problem.Thanks,,

Answer Source

simple use join

select t1.*,t2.* from t3 
join t1 on t1.ID=t3.table1_ID 
join t2 on t2.ID=t3.table2_ID