tags:

views:

15

answers:

1

I have these tables:

client

  • idclient
  • name
  • reference

address

  • idaddress
  • idclient

inv

  • idinvoice
  • idaddress
  • datetime
  • total

payment

  • idpayment
  • idinvoice
  • pdatetime
  • amount

into - name, reference, time, idpayment, idinvoice, amount

i.e. datetime and pdatetime as time. inv.total as negative amount. Where idaddress = 9

A: 

OK, I'm making quite a few assumptions about what you're asking, but it looks like you are going for this:

select
    c.name
    , c.reference
    , c.pdatetime as time
    , p.idpayment
    , i.idinvoice
    , p.amount
from
    payment p
    inner join inv i
        on p.idinvoice = i.idinvoice
    inner join address a
        on i.idaddress = a.idaddress
    inner join client c
        on a.idclient = c.idclient

add whatever filtering you need in a where clause

wshato
what about inv.totalinv.total as negative amountIf there are 3 invoice and 3 payments, I would expect 6 rows. 3 rows of column idpayment would be NULL and 3 rows of idinvoice would be NULL too.
roslan