Sin5k4
Sin5k4

Reputation: 1626

SQL conditionally update based on 2 different values

I want to update a field based on a where IN () clause but i also want the update the rest of the values using WHERE NOT IN()..For example:

UPDATE TABLE SET COLUMN1 = X WHERE COLUMN2 IN (1,2,3)
UPDATE TABLE SET COLUMN1 = Y WHERE COLUMN2 NOT IN (1,2,3)

To simply put it ,is there a way to combine these two queries?

Upvotes: 0

Views: 56

Answers (1)

Tomalak
Tomalak

Reputation: 338128

UPDATE 
  TABLE
SET 
  COLUMN1 = CASE WHEN COLUMN2 IN (1,2,3) THEN X ELSE Y END

Upvotes: 8

Related Questions