I have this query
Update loans set fine = case
when DATEDIFF((
(SELECT * from (SELECT loans.due_date FROM loans where users_id = 1) AS l1))
,DATE(NOW())) > 0 THEN 1
ELSE fine
END
WHERE users_id =1;
From table
+-------------+
| Field |
+-------------+
| users_id |
| books_isbn |
| aquire_date |
| due_date |
| fine |
+-------------+
It's work with user that have just one 'loans' but I don't know how to make it work with several 'loans' of one user. =(
I would expect a query to look someting like this:
Update loans l
set fine = 1
where users_id = 1 and l.due_date < curdate();
It is a little tricky to figure out the exact logic without sample data and desired results.