For this query, I suggest applying the WHERE >= CURDATE() condition, and then SELECT MIN(dated) using GROUP BY client_id :
SELECT b.client_id, MIN(b.dated) FROM banquet b WHERE b.dated >= CURDATE() GROUP BY b.client_id;
From this, you can add the required JOIN table to the client table to get the client name:
SELECT b.client_id, c.name, MIN(b.dated) FROM banquet b INNER JOIN client c ON c.id = b.client_id WHERE b.dated >= CURDATE() GROUP BY b.client_id;
SQLFiddle: http://sqlfiddle.com/#!9/aded8/18
CHANGE NEW PART OF QUESTION:
Based on the new information you added, asking how to handle zeros and the food column, I made some changes. This updated query processes possible null values ββ(by changing the WHERE clause) in a dated format, and also includes food information.
SELECT b.client_id, c.name, MIN(b.dated) AS dated, IFNULL(b.meal, '-') AS meal FROM banquet b INNER JOIN client c ON c.id = b.client_id WHERE b.dated >= CURDATE() OR b.dated IS NULL GROUP BY b.client_id;
or you can take some of this and combine it with Gordon Linoffβs answer, which sounds like it will work best.
New SQLFiddle: http://sqlfiddle.com/#!9/a4055/2
Stidgeon
source share