Similar to this question : SQL Statement with multiple SETs and WHEREs
Is there a way to perform multiple sets, as shown below.
UPDATE table
SET ID = 111111259
SET Name = "Bob"
SET Phone = 1111111261
WHERE ID = 2555
Thanks.
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. This example uses the WHERE clause to define multiple conditions, but instead of using the AND condition, it uses the OR condition.
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.
If you have worked with SQL databases before, you might have come across the statement WHERE 1=1. It is a common statement that is used to return all the records from a given table. The statement where 1=1 in SQL means true. It is the same operation as running the select statement without the where clause.
The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions.
This is possible,
UPDATE table SET Name = 'aaa', Col2 = 'bbb' WHERE ID IN (2555, 2666)
What you are asking for is setting multiple values to same column and same row.
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