Muhammad Usman Muhammad Usman - 3 months ago 7
MySQL Question

Query Syntax Error, with DATE_ADD function

Here is my query

SELECT donors.Name FROM donors JOIN donorsRecord ON donors.id = donorsRecord.id
WHERE NOW() > DATE_ADD (donorRecord.donationDate, INTERVAL 3 MONTH)


What I want to acheive is that I want to get all the donors who haven't donated blood in the last 3 month. But I only need to get their names, not all of their information. But I'm getting all of their records, when I only need one. Can anyone help ?

Answer
SELECT donors.Name FROM donors JOIN donorsRecord ON donors.id = donorsRecord.id
WHERE NOW() > DATE_ADD(donorRecord.donationDate, INTERVAL 3 MONTH)
group by donors.id;
Comments