Muhammad Usman Muhammad Usman - 1 year ago 65
SQL Question

Get Last Record of each donor

I am working on a BDS feature for a website in Laravel. Now I've tried asking this question twice here, but somehow I'm not able to ask it correctly, so I'll try to give it 1 last try.

I have 2 tables Donors and DonorRecords. What I want to to is to get all donors and their latest donation date only and only if they have not donated blood in last 3 month. I've tried it by both ways. Eloquent and Query.

Following is my query that I'm using:

SELECT,, donors.address, donors.blood_group, donors.area, MAX(donor_records.donation_date) AS d_date FROM donor_records JOIN donors ON = WHERE NOW() > DATE_ADD(donor_records.donation_date, INTERVAL 90 DAY)

Following are records in my database tables.


enter image description here


enter image description here

Now, But when I execute the query I only get the record with the donation date "2016-04-12" and not the other one. So can anyone help me with this 1 last time. It doesn't matter if it's from Eloquent or from DB side, both will work fine.

Answer Source
SELECT donors.Name FROM donors JOIN donorsRecord ON =
WHERE NOW() > DATE_ADD(donorRecord.donationDate, INTERVAL 3 MONTH)
group by;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download