I have 2 tables, debtor_information and debtor_money. This is an one to many relationship debtor_money having multiple records related to 1 record in debtor_information.
What I want I actually accomplish it with the following query. just that i don’t want dupe.
SELECT DISTINCT(D.debtor_id),D.fname,D.lname,M.lastDate FROM debtor_information D join debtor_money M on (D.debtor_id=M.debtor_id)
WHERE D.creditor_id='457456' AND D.debtor_id NOT IN (SELECT `debtor_id` FROM debtor_money WHERE `balance` > 0)
In plain words what I want to retrieve from the database is debtors on both table (It’s possible that a debtor don;t have related data on the second table ) that is why i used
join debtor_money M on (D.debtor_id=M.debtor_id)
also if a debtor has a money loan with balance dont show at all
AND D.debtor_id NOT IN (SELECT debtor_id
FROM debtor_money WHERE balance
> 0)
Again in plain words:
I want debtors on both tables and debtors who has no records with balance on debtor_money.