-1
I have two tables equal fields, ACCOUNTS TO PAY and ACCOUNTS TO RECEIVE, I need to generate a report taking the value Credit - Debit and leaving result, someone can help me, I’m picking for this, below the select I’m using and the link with print of the test result I have in the database.
https://www.cloudvine.com.br/exemplo.png
SELECT
tb_cr.tb_cr_credito AS tb_cr_credito,
tb_cr.tb_cr_id_fornecedor AS tb_cr_id_fornecedor,
tb_cr.tb_cr_dt_Lancamento AS tb_cr_dt_Lancamento,
tb_cr.tb_cr_vencimento AS tb_cr_vencimento,
tb_cr.tb_cr_descricao AS tb_cr_descricao,
tb_cr.tb_cr_valor AS Credito,
'' AS Debito,
tb_cr.tb_cr_situacao AS tb_cr_situacao
FROM tb_cr
WHERE tb_cr.tb_cr_situacao = 'Recebido'
UNION
SELECT
tb_cp.tb_cp_debito AS tb_cp_debito,
tb_cp.tb_cp_id_fornecedor AS tb_cp_id_fornecedor,
tb_cp.tb_cp_dt_Lancamento AS tb_cp_dt_Lancamento,
tb_cp.tb_cp_vencimento AS tb_cp_vencimento,
tb_cp.tb_cp_descricao AS tb_cp_descricao,
'' AS Credito,
tb_cp.tb_cp_valor AS tb_cp_valor,
tb_cp.tb_cp_situacao AS tb_cp_situacao
FROM tb_cp
where tb_cp.tb_cp_situacao = 'Pago'
See if it helps https://answall.com/questions/305445/consultar-dados-de-duas-tabelas-diferentes-e-listar-sem-unir-dados
– Motta