Empty array with Inner Join

1

I have some related tables, to do a SELECT brings me all the normal info and INNER JOIN , but there is a table of tickets that I have, I'm doing INNER JOIN , now when I go to detail a vehicle, the info that normally brings me is only shown when I have a ticket registered, and the vehicles that do not have a ticket do not bring me anything, I made a var_dump and it comes empty unless that vehicle had at least one ticket registered if it brings me all the information.

SELECT * FROM vehiculos
   INNER JOIN boletas ON vehiculos.control = boletas.control
WHERE vehiculos.control = :control

If I remove the INNER JOIN then if it brings me back all the info, but of course it already throws me error where I was showing the information of the tickets.

    
asked by Edy Lasso 17.04.2017 в 16:42
source

2 answers

0

Instead of using INNER JOIN use LEFT JOIN

SELECT * FROM vehiculos
LEFT JOIN boletas ON vehiculos.control = boletas.control
WHERE vehiculos.control = :control 
    
answered by 17.04.2017 / 16:43
source
0

You could use RIGHT JOIN and also try with the previous answer, the important thing is that when there is information in one table and in the other not the condition of INNER JOIN is not fulfilled, so you should use RIGHT O LEFT showing the results of the mother table even if it does not have relationship records. Example with Graphic

      SELECT vehiculos.control as boletavehiculo, boletas.control as 
      boletacontrol FROM vehiculos 
      LEFT JOIN boletas ON boletavehiculo = boletacontrol 
      WHERE boletavehiculo = :control 
    
answered by 17.04.2017 в 17:03