Column ambiguous

Asked

Viewed 78 times

0

I have a problem with the code that I can’t understand. The postgres always points to the error _"column Reference "pro_codigo" is ambiguous"_, but I gave the proper "nicknames" to column pro_codigo. I can’t see the point.

SELECT DISTINCT "m"."mov_data",
                (CASE
                     WHEN mov_entrada = 'T' THEN 'Transferência'
                     WHEN mov_entrada='E-SI' THEN 'Entrada por Saldo de Implantação'
                     WHEN mov_entrada='E-C' THEN 'Entrada por Concorrência'
                     WHEN mov_entrada='E-DL' THEN 'Entrada por Dispensa de Licitação'
                     WHEN mov_entrada = 'E-CONV' THEN 'Entrada por Convite'
                     WHEN mov_entrada = 'E-D' THEN 'Entrada por doação'
                     WHEN mov_entrada = 'E-P' THEN 'Entrada por Pregão'
                     WHEN mov_entrada = 'E-AE' THEN 'Entrada por Ajuste de Estoque'
                     WHEN mov_entrada = 'E-EVENTUAL' THEN 'Entrada por Entrada Eventual'
                     WHEN mov_entrada = 'E-O' THEN 'Entrada Ordinária'
                     WHEN mov_entrada = 'E-TP' THEN 'Entrada por Tomada de Preços'
                     WHEN mov_entrada = 'E-INEX' THEN 'Entrada por Inexigibilidade'
                     WHEN mov_entrada = 'E-PER' THEN 'Entrada por Permuta'
                     WHEN mov_entrada = 'E' THEN 'Entrada por Nota Fiscal de Compra'
                     WHEN mov_entrada = 'M' THEN 'Entrada por Emprestimo'
                     WHEN mov_entrada= 'I' THEN 'Entrada por Inventário'
                     WHEN mov_entrada = 'O' THEN 'Outras Entradas'
                     WHEN mov_entrada = 'V' THEN 'Entrada por Devolução'
                 END) AS "mov_entrada",
                "m"."mov_codigo",
                "f"."for_nome",
                "u"."usr_nome",
                "s".*
FROM "movimento" AS "m"
INNER JOIN "fornecedor" AS "f" ON f.for_codigo=m.for_codigo
INNER JOIN "usuarios" AS "u" ON u.usr_codigo=m.usr_codigo
INNER JOIN "itens_movimento" AS "ite" ON ite.mov_codigo=m.mov_codigo
INNER JOIN "setor" AS "s" ON s.set_codigo=m.set_entrada
INNER JOIN "produto" AS "p" ON p.pro_codigo=ite.pro_codigo
WHERE (mov_tipo = 'E')
  AND (mov_data >= '01/06/2018')
  AND (mov_data <= '06/10/2018')
  AND (set_entrada = 4)
  AND (pro_codigo = 204)
ORDER BY "set_codigo" ASC,
         "mov_data" ASC
  • From which table is the column mov_entrada?

  • I think here AND (pro_codigo = 204) table name was missing.

  • I think you missed the table alias in the WHERE and also SELECT columns.

  • I tried to put the nickname p as in the line of the product Inner Join... however the error remains the same

1 answer

2


Since you have many columns, the ideal way not to forget any field is to reference the columns of all fields; try the where thus:

WHERE (m.mov_tipo = 'E')
  AND (m.mov_data >= '01/06/2018')
  AND (m.mov_data <= '06/10/2018')
  AND (m.set_entrada = 4)
  AND (p.pro_codigo = 204)
ORDER BY s.set_codigo ASC, m.mov_data ASC
  • 1

    I followed the ways of you and the comments up and it worked thank you.

  • in very large consultations becomes difficult keep up with a field.. it is good to name the damned =p

Browser other questions tagged

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