I'm a bit confused about the proper way to update one table, based on the values of corresponding rows in another table.
Here is the query I have:
UPDATE
features,
images
SET
features.deleted = 1
WHERE
features.objectType = 'image'
AND images.id = features.objectId
AND images.uploaded = 0;
My goal:
I want to set the
features.deleted
column value for all rows in thefeatures
table to be1
, only if the correspondingimages.uploaded
value for that associated image is0
.
Business logic:
I want to go over all the images that been created in my app, and if the image wasn't successfully uploaded, I want to delete the corresponding
features
record.
I believe this works, but have been having a hard time finding specific examples using my approach (most suggest using join
s).
My concern is that the UPDATE
query is too general: I just want to make sure that it will only update feature
records that have their associated image
record with an uploaded
value of 0
.
Thanks for any guidance/confirmation!