Unknown column in 'field list' in INNER JOIN code using COUNT()

Asked

Viewed 256 times

-2

My SQL code has the following error:

Error Code: 1054. Unknown column 'venda.cd_venda' in 'field list'

Does not return the count of the records I want for me to filter them into a <table></table>in PHP, what would be the error?

SELECT count(cliente.cd_cliente) AS id_cliente, COUNT(funcionario.cd_funcionario) AS id_funcionario, 
COUNT(fornecedor.cd_fornecedor) AS id_fornecedor, COUNT(itens_compra_fornecedor.cd_itens_compra_fornecedor) AS id_compra,
COUNT(produto.cd_produto) AS id_produto, itens_venda.cd_itens_venda,
COUNT(venda.cd_venda) AS id_venda, itens_devolucao.cd_itens_devolucao,
COUNT(devolucao.cd_devolucao) AS id_devolucao FROM devolucao
INNER JOIN cliente ON cliente.cd_cliente = itens_venda.cd_cliente
INNER JOIN funcionario ON funcionario.cd_funcionario = itens_venda.cd_funcionario
INNER JOIN produto ON produto.cd_produto = itens_venda.cd_produto
INNER JOIN itens_compra_fornecedor ON itens_compra_fornecedor.cd_fornecedor = fornecedor.cd_fornecedor
INNER JOIN fornecedor ON fornecedor.cd_fornecedor = itens_compra_fornecedor.cd_fornecedor
INNER JOIN itens_venda ON itens_venda.cd_itens_venda = venda.cd_itens_venda
INNER JOIN itens_devolucao ON itens_devolucao.cd_itens_devolucao = devolucao.cd_itens_devolucao
GROUP BY itens_venda.cd_itens_venda, itens_devolucao.cd_itens_devolucao;
  • 1

    The mistake says about venda.cd_venda, has no table venda in the query

  • @Rafaeltavares COUNT(venda.cd_venda)

  • 1

    That’s not a table, it still doesn’t have a table venda in the query.

  • 1

    Has devolucao, cliente, funcionario, produto, itens_compra_fornecedor, fornecedor, itens_venda, itens_ devolucao Has not venda.

  • 1

    In the query there is no mention of the table vendas so that some of your columns can be referenced in the query itself. Hence the error.

1 answer

1

This error occurs because in your query there is no 'itens_venda.cd_itens_venda' column Check your database to see if this column actually exists.

  • Yes, there is cd_itens_sale in itens_sale table.

  • There is no reference to the table vendas. There is a reference for one of your fields.

Browser other questions tagged

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