开发者

Update a row and delete another one

开发者 https://www.devze.com 2023-03-28 12:04 出处:网络
I\'m trying to update a table wit开发者_运维知识库h values from another table. What I want to do is, each time an update happens, to delete the row in the table where I\'m getting the data from.

I'm trying to update a table wit开发者_运维知识库h values from another table. What I want to do is, each time an update happens, to delete the row in the table where I'm getting the data from.

This is my code so far:

UPDATE city SET city_longitude = (SELECT city_longitude FROM cities WHERE city.shortCity = cities.city_name OR city.cityName = cities.city_name LIMIT 1) LIMIT 100

This update is working so far, but I have to delete the rows where I'm updating FROM (the ones in the cities table).

Is there any way to do this?


delete from cities where some_id = 1

Are you unable to do something along these lines after your UPDATE statement has finished? You may want to have something that actually confirms your UPDATE statement succeeded and then only DELETE afterwards.

The safer alternative is to have a flag called isUpdated or something along those lines, which you can set to true after an UPDATE but you keep the row in the original table.

0

精彩评论

暂无评论...
验证码 换一张
取 消