I have a clientlist table a payments table and a calls table
I want to return a row consisting of most of the clientlist table the date and amount of last payment and same for date of last call.
I have written a query that almost (so not at all) works .. it works as expected as long as a payment and call exist on the joined tables. if one or other does not exist the query does not return a row.
what i would like is the client data returned regardless of payment and calls data.
SELECT clientlist.ID, clientlist.FirstName, clientlist.LastName, clientlist.`Herd Number`, clientlist.Address1, clientlist.Address2, clientlist.Address3, clientlist.County,
clientlist.postcode, clientlist.Mobile, clientlist.AuditDue AS `Cert Expiry`,p1.dateofpayment,p1.amt ,c1.dateofcall, a1.link,a1.dateOfAudit
FROM agritxtdev.clientlist left join payments p1
on clientlist.ID=p1.clientnum
left join calls c1
on clientlist.id= c1.clientnum left join auditdate a1 on a1.client = clientlist.id
where p1.id = (Select MAX(id) from payments p2 where p1.clientnum=p2.clientnum)
AND c1.id= (Select MAX(id) from calls c2 where c1.clientnum=c2.clientnum)
order by clientlist.ID
I would really appriecate any help ye can give me with this one.
im fairly certain the my issue is in here but im lost as to another approach
where p1.id = (Select MAX(id) from payments p2 where p1.clientnum=p2.clientnum)
AND c1.id= (Select MAX(id) from calls c2 where c1.clientnum=c2.clientnum)
thanks in advance Peter