1054 - Unknow colunm in on clause

2

What is wrong with this query?

SELECT 
  clientes.idClientes, 
    clientes.nome, 
    clientes.bloqueado, 
    planosclientes.idPlanos, 
    planos.nome, 
    enderecos.bairro, 
    enderecos.cidade                    
FROM 
    planosclientes INNER JOIN clientes  ON planosclientes.idClientes       =  clientes.idClientes                 AND
    planosclientes INNER JOIN planos    ON planosclientes.idPlanos         =  planos.idPlanos                     AND
    planosclientes INNER JOIN enderecos ON planosclientes.idPlanosClientes =  enderecos.idPlanosClientes
WHERE 
    clientes.bloqueado = 's' AND 
    enderecos.tipoEndereco = 'i'

You are giving the following error:

Unknow colunm 'planosclientes' in on clause.

But there is no 'customer plans' column in the on clauses. What you have are 'flat' tables.

What error is this?

    
asked by anonymous 05.10.2015 / 14:39

2 answers

2

I believe that this way the query is correct, you do not need to repeat the name in every INNER JOIN

  

Unknow colunm 'plansclients' in on clause.

The error happens because the syntax says, together with the client table where the ids are equal and client plans (it is a table and not a column)

planosclientes INNER JOIN clientes
ON planosclientes.idClientes =  clientes.idClientes AND planosclientes
-----------------------------------------------------^----^(tabela) 

Switch to:

SELECT 
  clientes.idClientes, 
    clientes.nome, 
    clientes.bloqueado, 
    planosclientes.idPlanos, 
    planos.nome, 
    enderecos.bairro, 
    enderecos.cidade                    
FROM 
    planosclientes
    INNER JOIN clientes ON planosclientes.idClientes = clientes.idClientes 
    INNER JOIN planos ON planosclientes.idPlanos = planos.idPlanos 
    INNER JOIN enderecos ON planosclientes.idPlanosClientes =  enderecos.idPlanosClientes
WHERE 
    clientes.bloqueado = 's' AND 
    enderecos.tipoEndereco = 'i'

If MySQLi is changed, change s and i to ? % data type specified in bind_param() .

    
05.10.2015 / 14:46
1

Your query is strange. I gave a query as I believe it should be.

SELECT 
    clientes.idClientes, 
    clientes.nome, 
    clientes.bloqueado, 
    planosclientes.idPlanos, 
    planos.nome, 
    enderecos.bairro, 
    enderecos.cidade                    
FROM 
    planosclientes 
INNER JOIN 
    clientes  ON planosclientes.idClientes       = clientes.idClientes
INNER JOIN 
    planos    ON planosclientes.idPlanos         = planos.idPlanos
INNER JOIN 
    enderecos ON planosclientes.idPlanosClientes = enderecos.idPlanosClientes
WHERE 
    clientes.bloqueado = 's' AND 
    enderecos.tipoEndereco = 'i'
    
05.10.2015 / 14:44