HPWD HPWD - 1 year ago 60
MySQL Question

MySQL Query needed to update existing date by 8

I have a mysql database and there are only 4 records (out 10 of 10,000's) that need to have their date field routinely updated by 8 days. The other records need to be left alone. This has to be able to be run week after week after week...

Data looks like this (lot more data available). The primary ID will be constant and is not displayed below.

Starting Data looks like:

'title 1','2016-09-03 00:00:00'
'title 1','2016-09-04 00:00:00'
'title 2','2016-09-05 00:00:00'
'title 2','2016-09-06 00:00:00'
'title 10','2016-09-10 00:00:00'
'title 10','2016-09-11 00:00:00'
'title 11','2016-09-12 00:00:00'
'title 11','2016-09-13 00:00:00'

Ending Data looks like:

'title 1','2016-09-07 00:00:00'
'title 1','2016-09-08 00:00:00'
'title 2','2016-09-09 00:00:00'
'title 2','2016-09-10 00:00:00'
'title 10','2016-09-14 00:00:00'
'title 10','2016-09-15 00:00:00'
'title 11','2016-09-16 00:00:00'
'title 11','2016-09-17 00:00:00'

It doesn't matter what the existing date is, the query needs to simply add 4 days to it and update the row accordingly.

Can I do this in one statement or do I need to perform a query to select the data, then perform a second query to do the the update?

Answer Source

Something simple like this could work

UPDATE titles
WHERE id IN (1,2,3,4);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download