SQL Server UPDATE table, where is the ID in SELECT?

I have a table where I want to update all rows with an identifier that exists as a result of the selection.

My pseudo code:

UPDATE mytable as t SET t.status = 'PM' WHERE t.ID EXISTS IN (select ID from ...) 

I managed to make a select statement, now I want to use the result of the select statement to update the table.

+6
source share
2 answers

If you delete the existing one, you have a valid request from what I can say.

 UPDATE mytable SET status = 'PM' WHERE id IN (select ID from ...) 

Works for me in MySql 5.5, I don’t know which database you are using.

+16
source

You cannot use substitution in an UPDATE statement. The original query should be good if you do not consider the part β€œlike t” and both β€œt.”.

+1
source

Source: https://habr.com/ru/post/893839/


All Articles