Error doing Left Join. The identifier consisting of several parts ... could not be linked

0

First of all, explain what I am trying to do so that you understand my problem. I am developing a web platform based on PHP to perform the maintenance of the different types of equipment that may be in an empesa (High, low and modification thereof)

My problem is that I have SIM data in one table, in another data phone and finally phone types. The phone and SIM tables are related by the idSIM. Since there are telephones that do not have any assigned SIM, I want to show them in the phone list, but with the current SQL they do not come out (since a condition is that the idSIM matches) Current SQL:

SELECT * 
FROM 
    Telefonia_Equipamiento,
    Equipamiento_TipoTelefono,
    SIM_Equipamiento 
WHERE 
    Telefonia_Equipamiento.activo = 1 
    AND 
    Telefonia_Equipamiento.tipoTelefono = Equipamiento_TipoTelefono.idTipo 
    AND 
    Equipamiento_TipoTelefono.descripcion='Empleados' 
    AND 
    Telefonia_Equipamiento.idSIM = SIM_Equipamiento.idSIM  
ORDER BY 
    Telefonia_Equipamiento.idTelefonia";

I'm trying to make a left join to show the phones that do not have SIM, but I get the error of the title

SQL with Left Join:

SELECT *
FROM 
    Telefonia_Equipamiento,
    Equipamiento_TipoTelefono
LEFT JOIN 
    SIM_Equipamiento 
ON 
    Telefonia_Equipamiento.idSIM=SIM_Equipamiento.idSIM
WHERE 
    Telefonia_Equipamiento.activo = 1 
    AND 
    Telefonia_Equipamiento.tipoTelefono = Equipamiento_TipoTelefono.idTipo
    AND 
    Equipamiento_TipoTelefono.descripcion='Empleados';

If you need more information, data or whatever, do not hesitate to ask me. Thanks in advance

    
asked by V.Vallejo 18.05.2017 в 11:08
source

2 answers

1

I think it would be more correct to have an inner join for the entity that contains the type of phone, since any phone that is loaded must have assigned a type of phone. Try it this way:

SELECT  *
FROM    Telefonia_Equipamiento
        INNER JOIN  Equipamiento_TipoTelefono ON Telefonia_Equipamiento.tipoTelefono = Equipamiento_TipoTelefono.idTipo
        LEFT JOIN   SIM_Equipamiento ON Telefonia_Equipamiento.idSIM = SIM_Equipamiento.idSIM
WHERE   Telefonia_Equipamiento.activo = 1
        AND Equipamiento_TipoTelefono.descripcion = 'Empleados'

I hope it serves you.

    
answered by 18.05.2017 / 12:39
source
1

If I'm not wrong to take the table Equipment_TypeTelephone to another left join, since it does not allow to have left join with join using the where to link them

SELECT *
FROM 
    Telefonia_Equipamiento       
LEFT JOIN 
    SIM_Equipamiento 
ON 
    Telefonia_Equipamiento.idSIM=SIM_Equipamiento.idSIM
LEFT JOIN 
     Equipamiento_TipoTelefono
ON 
    Telefonia_Equipamiento.tipoTelefono = Equipamiento_TipoTelefono.idTipo    
WHERE 
    Telefonia_Equipamiento.activo = 1 
    AND 
Equipamiento_TipoTelefono.descripcion='Empleados';
    
answered by 18.05.2017 в 11:37