noOne noOne - 2 years ago 88
MySQL Question

two inner join in one sql statement

What's wrong here ? i just want to display all the item in item_tb with 2 different group , vicma and branch but it returns nothing. It only works in one inner join but when i join the other one it display nothing.

|item_tb | vicma_tb | branch_tb |
| | vID - PK | id-PK |
|branchID-FK | | |
|vicma - FK | | |

$sql = "
SELECT item_tb.*
, branch_tb.*
, vicma_tb.*
from item_tb
JOIN branch_tb
on item_tb.branchID =
JOIN vicma_tb
on item_tb.vicma = vicma_tb.vID ";

Answer Source

Seems like you need to do a LEFT JOIN instead of INNER JOIN. LEFT JOIN will return all values from your original table and NULL if there is no match. Try:

SELECT  item_tb.*, branch_tb.* , vicma_tb.* from item_tb 
LEFT JOIN  branch_tb on item_tb.branchID = 
LEFT JOIN vicma_tb on item_tb.vicma = vicma_tb.vID 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download