I have these tables:
client(idclient, name, reference)
address(idaddress, idclient)
inv(idinvoice, idaddress, total, datetime)
payment(idpayment, idinvoice, amount, pdatetime)
INTO something like
client reference time idinvoice idpayment amount
xyz a2345 2010-03-01 2342 NULL -(amount)
xyz a2345 2010-02-12 2341 NULL -(amount)
xyz a2345 2010-03011 NULL 2222 amount
inv.total as amount, datetime and pdatetime as time, where idaddress = 9