0

I have been trying to update a date for all rows in a table by 11 days using a correlated subquery. One problem I have run into is that MySql will not let me update the table I am selecting from in my subquery. I was able to work around that by saving the results from the subquery as a temporary table. This works when I have a defined value for my where clause in the subquery. However, when I try to reference the outer query (ie: vm.psname = v.psname) I get "unknown column 'v.psname' in 'where clause' here is my query:

UPDATE cloud.vms v SET expirationdate=(
    SELECT date FROM (
        SELECT DATE_ADD(
            (SELECT expirationdate
             FROM cloud.vms vm
             WHERE vm.psname=v.psname),
             INTERVAL 11 DAY) 
        AS date)
    AS tmptbl)

I have also looked at using an inner join (example from previous post). However, I am not sure how to do this.

Community
  • 1
  • 1
ferics2
  • 5,241
  • 7
  • 30
  • 46

1 Answers1

1

I didn't try it, but why aren't you just doing the DATE_ADD, like this

 UPDATE cloud.vms set expirationdate = DATE_ADD(expirationdate, INTERVAL 11 DAY) ;
Nettogrof
  • 2,116
  • 2
  • 15
  • 22
  • Haha, sometimes the easy answers are right in front of my face. I guess I was trying to be too smart. Thanks Nettogrof – ferics2 Apr 24 '12 at 16:53