I am developing cash flow from my company and am encountering a difficulty.
I have two different tables. A table is tb_compras (id, nfe, value, date) and then I have another one also tb_compras_pagamentos (id, buy_id, pay_value, date).
I need to create an equal bank checking account. I'm launching the purchases and payments. Purchase is a debt and deposit a credit. Ex:
Data | Descrição | Crédito | Débito | Total 12/06 Cupom fiscal 02 -100,00 -100,00 13/06 Depósito 233 +80,00 -20,00 15/06 Cupom fiscal 11 -200.00 -220.00 17/06 Depósito 1223 +400,00 +180,00
I'm not able to do the select to get the results of the two tables in a single query and sort by the date to be able to list this way. Remembering that the tb_compra_pagamentos table is related to purchases.
I thought about using this query, but it is giving error in select:
SELECT valor_total_pedido AS valor FROM tb_pedido_compra WHERE fornecedor = '$this->id' UNION ALL SELECT valor FROM tb_pedido_compra_historico_pagamento WHERE pedido_compra = tb_pedido_compra.id