I am wondering if this is a valid query:
UPDATE table SET ID = 111111259 WHERE ID = 2555 AND SET ID = 111111261 WHERE ID = 2724 AND SET ID = 111111263 WHERE ID = 2021 AND SET ID = 111111264 WHERE ID = 2017
You can use the OR condition in the WHERE clause to test multiple conditions where the record is returned if any one of the conditions are met.
Can we UPDATE multiple tables with a single SQL query? No, only 1 table can be updated with an UPDATE statement. However, you can use a transaction to ensure that 2 or more UPDATE statements are processed as a single unit-of-work.
The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions.
SQL AND, OR and NOT OperatorsThe WHERE clause can be combined with AND , OR , and NOT operators. The AND and OR operators are used to filter records based on more than one condition: The AND operator displays a record if all the conditions separated by AND are TRUE.
NO!
You'll need to handle those individually
Update [table] Set ID = 111111259 WHERE ID = 2555 Update [table] Set ID = 111111261 WHERE ID = 2724 --...
Best option is multiple updates.
Alternatively you can do the following but is NOT recommended:
UPDATE table SET ID = CASE WHEN ID = 2555 THEN 111111259 WHEN ID = 2724 THEN 111111261 WHEN ID = 2021 THEN 111111263 WHEN ID = 2017 THEN 111111264 END WHERE ID IN (2555,2724,2021,2017)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With