mysqlsqlsql-types

SQL Update Int to Equal Int on another Table


I want the images.url_id value to be the same as the urls.url_id value.

This is what I have come up with based off of this, but it doesn't work.

update images
set images.url_id = urls.url_id
from images inner join urls
on images.url_id = urls.url_id
;

Any help would be appreciated greatly.


Solution

  • This doesn't work, because you are trying to update images.url_id with value of urls.url_id on condition that those values are equal. You already know they are not.

    If you want to set images.url_id equal to those from urls.url_id the way you want it you need to have a matching column to perform such operation for each row.