I am executing a query that obviously contains a subquery in MySQL.
Let me just jump into the code:
SELECT DATEDIFF(CURDATE(),
(SELECT due FROM checkOut JOIN People ON checkOut.p_id = People.p_id
WHERE CASE WHEN DATE_SUB(date_add(CURDATE(),INTERVAL 4 MONTH), INTERVAL 3 MONTH)
>= checkOut.checkTime THEN 1 ELSE 0 END ORDER BY checkOut.due)
);
The main query is the SELECT DATEDIFF(). Within that is my subquery which essentially searches through the table to look for items that are overdue based on an interval. I know that there will be multiple rows returned from the query and that it will not work with how I currently have it set up.
What I want are multiple values to be returned from my SELECT DATEDIFF(), so that I can loop through it with php later. To elaborate, I want each of the rows returned in the subquery to have an associated value from DATEDIFF(). How can I modify this query to do what I want? Or if anyone has a better method, please let me know.
Any help is appreciated.
In case you are wondering the why there is a DATE_ADD() within the DATE_SUB(), it is to simply make the query work for today.