Join multiple tables - query not working if problem with foreign keys

Hi everyone,

please excuse the convoluted explanation. Hopefully someone can make sense of it.

I’m joining a number of tables. I’ve noticed that the query fails completely if I don’t set all of the foreign keys properly. For example, table3 might have a column (id_two) which contains the foreign keys of another table. Now I need to manually add a number (key) to each field in the id_two column in table 3. The primary keys range from 1 upwards. If I add a 0 instead, the query will fail. Of course I understand that the join between the two tables will no longer work. What I don’t understand is why the remainder of the joins don’t continue to work. Does one JOIN failure break the query?

Thanks for your help!!!

$q = "SELECT  a.column1, b.column1, b.column2, b.column3, c.column1, c.column2, d.column1  FROM table1 AS a
INNER JOIN table2  AS b USING (id_one)
INNER JOIN table3 AS c USING (id_two)
INNER JOIN table4 AS d USING (id_three)
WHERE b.column1 = '$name' ";


of course :slight_smile:

Hi there Rudy,

thank you for the confirmation! I was hoping you’d say the other joins would still work, but alas…

technically, they are all working just fine, just not returning what you hoped for

:slight_smile: