Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql: export single row, but with all dependencies

Tags:

sql

mysql

export

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?

like image 825
flybywire Avatar asked Nov 14 '22 14:11

flybywire


1 Answers

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 
like image 131
andrewWinn Avatar answered Dec 05 '22 02:12

andrewWinn