Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql - query three tables

I have a relational database with three tables. The first containts id's that relate to the second. The second contains id's that relate to the third. The third contains the results I am after.

Is it possible with a single query to query an id in the first table which gives all results from the third table that relate to it?

Sorry I am new to mySQL.

like image 853
Mark Avatar asked Nov 30 '22 11:11

Mark


1 Answers

Mysql Join

Try this

select * from table1 t1
join table2 t2 on t1.t2ref = t2.id
join table3 t3 on t2.t3ref = t3.id

Add a where clause to search for certain rows in table1

where t1.field = 'value'
like image 170
Peter Lindqvist Avatar answered Dec 04 '22 08:12

Peter Lindqvist