Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Run UPDATE mySQL Query on Multiple Rows

I have a table like this

librarylog

patronName bookId dueDate
John 24 2024-01-14
Sam 42 2024-01-07
Bob 13 2024-01-07

I’m trying to create a SQL query which updates all the dueDate values and increases them by a week.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is what I had:

UPDATE librarylog SET dueDate = DATE_ADD((SELECT * FROM (SELECT dueDate FROM librarylog)tblTmp), INTERVAL 1 WEEK);

But this returns

#1242 - Subquery returns more than 1 row

>Solution :

The RHS of the update should just be the dueDate column wrapped in DATE_ADD:

UPDATE librarylog
SET dueDate = DATE_ADD(dueDate, INTERVAL 1 WEEK);  -- update all records
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading