Problems with SQL statement

2

I'm doing SQL queries and it does not work for me, do you know if the syntax is fine?

$consulta = "SELECT * 
        FROM TipoVehiculo
        INNER JOIN VehiculoFlota
        ON VehiculoFlota.idtipo=TipoVehiculo.idtipo
        INNER JOIN Empresa 
        ON Empresa.idnombreempresa=VehiculoFlota.idnombreempresa
        WHERE disponibilidad LIKE 'Si'";

Table TypeVehicle

idtipo  marca   modelo

22      seat    ibiza

Table VehiculoFlota

idmatricula     idtipo  idnombreempresa     disponibilidad  
locamatricula   22      juguetos            Si
33333           22      yoqse               Si
matriculayob    22      filomena            Si

Company Table

idnombreempresa

juguetos

yoqse

filomena
    
asked by javi fer 01.08.2017 в 13:21
source

2 answers

2

What is the problem you have?

It works for me: Example Here

  • In your WHERE you do not indicate which table the availability column belongs to, but because it is not present in another table that you use in your Query there is no problem Now, however, you should specify to which table it belongs to avoid future problems.
  • In the end you use the LIKE and as they mention it in the comnetarios if you are going to buy a value use = , if you are searching for wildcards you use LIKE , for example idmatricula LIKE 'matri%'
answered by 01.08.2017 в 16:03
0

try this.

SELECT *
FROM tbl_Empresa INNER JOIN (TipoVehiculo INNER JOIN VehiculoFlota ON VehiculoFlota.idtipo = TipoVehiculo.idtipo) ON Empresa.idnombreempresa= VehiculoFlota.idnombreempresa
 where disponibilidad='si';
    
answered by 01.08.2017 в 17:03