Query data from two different tables and list without joining data

0

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
    
asked by anonymous 08.06.2018 / 15:10

1 answer

0

If I understand correctly, just join the two tables and give a order by desc .

select * 
from tb_compras tc
join tb_compras_pagamentos tcp on tc.id = tcp.id_compra
order by tc.data desc

detail: from the header of the example you showed, I believe there are other table (s) and / or other fields in which you have spoken; there is no distinction between debit and credit in the tb_compras_pagamentos table to be displayed in the query

    
08.06.2018 / 15:19