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.
精彩评论