0
I am developing cash flow from my company and am encountering a difficulty.
I have two different tables. One table is tb_compras(id, nfe, value, date) and then I have another also tb_compras_pagamentos(id, id_compra, valor_pago, date).
I need to create an equal bank account. I am launching purchases and payments. Purchase is a debit 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 being able to select to take the results of the two tables in a single query and sort by date to be able to list like this. Remembering that the tb_compra_pagamentos table is related to purchases.
I thought to use this query, but 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
Where exactly the columns
credito
anddebito
enter the tablestb_compras
andtb_compras_pagamentos
?– Woss
select c.id, c.nfe, c.valor, c.data,p.id, p.id_compra,p.valor_pago,p.data, p.id from tb_compras_pagamentos Inner Join tb_compras on c.id = p.id_compra;
– Anderson Henrique
In this case I think you will have to use UNION so Voce UNE the data of table A and B without adding, and order by will understand that it is a single data block
– Marcelo
In the case of the SHOPPING table is the debit and the PAYMENTS table the credits
– Halan Schlickmann
I thought of something like this, but it is giving error in select: <pre>SELECT valor_total_order AS value FROM tb_pedido_purchase WHERE supplier = '$this->id' UNION ALL SELECT value FROM tb_pedido_shop histori_payment WHERE requested buy_purchase = tb_pedido_purchase.id</pre>
– Halan Schlickmann
fornecedor
is a field oftb_compras
? by his description, no (that would be the mistake?)– rLinhares
the question is very confusing... you say you want to join the tables "tb_compras" and "tb_compras_pagamentos", but the query you thought of using involves other tables of completely different name, namely "tb_pedido_compra" and "tb_pedido_compra_historico_pagamento". You can show an example of the data of each table to give an idea of the problem?
– nunks