I have a situation where I need to do an update on a very large set of rows that I can only identify by their ID (since the target records are selected by the user and have noth
How do you generate the IN clause?
If there is there another SELECT statement that generates those values, you could simply plug that into the UPDATE like so:
UPDATE TARGET_TABLE T
SET
SOME_VALUE = 'Whatever'
WHERE T.ID_NUMBER IN(
SELECT ID_NUMBER --this SELECT generates your ID #s.
FROM SOURCE_TABLE
WHERE SOME_CONDITIONS
)
In some RDBMses, you'll get better performance by using the EXISTS syntax, which would look like this:
UPDATE TARGET_TABLE T
SET
SOME_VALUE = 'Whatever'
WHERE EXISTS (
SELECT ID_NUMBER --this SELECT generates your ID #s.
FROM SOURCE_TABLE S
WHERE SOME_CONDITIONS
AND S.ID_NUMBER = T.ID_NUMBER
)