flybywire
flybywire

Reputation: 274062

mysql: export single row, but with all dependencies

Mysql question. I want to export one single row from one table with a catch: I want to pull together with it all the rows in all other tables referenced from the initial row by foreign keys - and referenced from the new rows too, recursively, until I get all rows that the initial one "needs to exist".

How can I do that?

Upvotes: 5

Views: 1444

Answers (1)

andrewWinn
andrewWinn

Reputation: 1786

Add more inner joins until you make it through your data structure

Select * from table1 t1 
inner join table2 t2 on
t1.pk = t2.fk
inner join table3 t3 on
t2.pk = t3.fk
.......
where t1.pk = {pk id number} limit 0,1 

Upvotes: 1

Related Questions