PHP/MySQL select query to go through four related tables in database -


i have select query , insert query follows:

$select_query = mysql_query("select trees, animals table1 gardens > '10000'", $mysql_connection); while ($row = mysql_fetch_array($select_query)) { $trees = $row['trees']; $animals = $row['animals']; $names = ?????????? // in order names, select query should go through table2 , table4  //and assigned names table3. please see schematic picture of tables. $insert_query = mysql_query("insert table6 (new_trees, new_animals, new_name) values ('$trees', '$animals', '$names')", $mysql_connection); } 

i want select , insert $trees, $animals , $names table. there no problem $trees , $animals variables, not know how select data $names. seen in schematic picture of tables, table1.id=table2.reference , table2.first_id gets values table4.id.

then, table4.second_id gets values table3.id , table3.name must selected in order satisfy $names variable in above-mentioned $insert_query. sorry if did not explain problem more clearly. please review picture , let me know solution?

schematic illustration of picture

lookup join clauses:

select   t1.id, t1.trees, t1.animals, t3.name   table1 t1   left join table2 t2     on t2.reference = t1.id   left join table4 t4     on t2.first_id = t4.id   left join table3 t3     on t4.second_id = t3.id    // select conditions 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -