Mysql ambiguous error

Asked

Viewed 28 times

0

I’m having an error in my Select

SELECT *,
SUM(IF(debito_credito_financeiro = 'D', valor_financeiro, 0)) AS debito,
SUM(IF(debito_credito_financeiro = 'C', valor_financeiro, 0)) AS credito,
(SELECT SUM(IF(debito_credito_financeiro = 'C', valor_financeiro, -valor_financeiro)) FROM cad_financeiro AS L2 WHERE cad_financeiro.id_financeiro >= L2.id_financeiro) AS saldo
FROM cad_financeiro
JOIN cad_trabalho ON cad_financeiro.id_trabalho = cad_trabalho.id_trabalho
JOIN cad_paciente ON cad_trabalho.id_paciente = cad_paciente.id_paciente
JOIN cad_cliente ON cad_paciente.id_cliente = cad_cliente.id_cliente
WHERE id_cliente = '8'
GROUP BY id_cliente, id_financeiro ORDER BY id_financeiro

it generates error, but when I remove the line

JOIN cad_cliente ON cad_paciente.id_cliente = cad_cliente.id_cliente

she works perfectly

1 answer

1


It happens because you have the WHERE id_cliente = '8', you have to put WHERE cad_cliente.id_cliente = '8'.

'Cause he’s messed up and he doesn’t know which one you’re referring to

Browser other questions tagged

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