sql - mysql nested select in update -


good morning,

i have problem updating database.

this orders table:

id | parent_id | type | paid 

now need update orders parent_id paid. have little trouble doing this, because of nested queries.

i tried this

update orders set orders.paid = now() (     select orders.parent_id     orders     orders.id = orders.parent_id ) 

but won't magic. can't :/

1 | null | 8 | 2015-20-09 12:00:00 2 | 1    | 7 | 0000-00-00 00:00:00 3 | 1    | 7 | 0000-00-00 00:00:00 4 | null | 8 | 2015-18-09 12:00:00 5 | 4    | 7 | 0000-00-00 00:00:00 

you may use join doing update as

update orders o1 join orders o2 on o2.id = o1.parent_id set o1.paid = now() o2.paid <> '0000-00-00 00:00:00' 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -