1054 - Unknow colunm in on clause

Asked

Viewed 64 times

2

what’s wrong with this consultation?

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’re making the following mistake:

Unknow colunm 'planosclientes' in on clause.

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

What mistake is this?

  • Your consultation seems wrong, there is a AND It was at the end compared to nothing. Identa better the code.

2 answers

2

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

Unknow colunm 'planosclientes' in on clause.

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

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

Change 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 changing s and the i by an intolerance ? the data type is specified only in bind_param().

1

It’s strange your query. I tweaked the 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'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.