I have a query which i am trying to get the last date and when i do, the purchdate and LastPayDate is the same for all the data. the query is below:
SELECT DISTINCT customer.custid,customer.compname,customer.balance AS balance,customer.phone,acctofficer.acctfullname AS acctoff, preAgg1.LastPayDate,customer.depot, MAX(mastorders.lastsuppdate) AS purchdate, MAX(mastorders.id) FROM customer,mastorders,acctofficer, (SELECT DISTINCT T.custid, Max(T.timestamp) AS LastPayDate FROM transactions AS T,customer AS C WHERE T.parttype='Receipt' AND T.custid=C.custid GROUP by T.custid) preAgg1 WHERE (STR_TO_DATE(mastorders.lastpaydate,'%d-%m-%Y') < DATE_SUB(CURDATE(), INTERVAL 30 DAY)) AND (STR_TO_DATE(mastorders.lastpaydate,'%d-%m-%Y')<> '0000-00-00') AND customer.balance>0 AND customer.custid=mastorders.custid AND acctofficer.acctoffid=mastorders.acctoff AND acctofficer.acctoffid=customer.acctoff AND customer.depot='$depot' GROUP by customer.custid,STR_TO_DATE(mastorders.lastpaydate, '%d-%m-%Y') ASC
Thanks for the help.