4
I am developing cash flow from my company and am encountering a difficulty.
I have two different tables. A table is a tb_compras(id, fornecedor, nfe, valor, data)
and then I have another table tb_compras_historico_pagamentos(id, id_compra, valor_pago, data)
.
I need to create an equal bank current account, cash flow of a particular SUPPLIER mine.
I’ll launch the shopping on tabela tb_compras
which in this case is a debiting(-) and payments in tabela tb_compras_historico_pagamentos
which in this case are the credits(+).
Then tb_compras is debit and tb_compras_historico_payments is 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 am unable to select to take the results of the two tables in a single select and sort by date to be able to list in the form of the example above.
Remembering that the table tb_compras_historico_pagamentos
is related to the table tb_compras
.
I thought to use the select below, but is giving error in select, I do not know if it is the ideal way for it.
Because in case I need to get all the table records tb_compras
and table tb_compras_historico_pagamentos
(that is linked with tb_purchases) and list all by date order to create the incoming cash flow and payments.
The select I’m trying is this, but unsuccessfully:
SELECT value FROM tb_shopping WHERE supplier = 'ID_FORNECEDOR' UNION ALL SELECT value FROM tb_buys_histori_payment where id_purchase = tb_compras.id