Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL multi SET with one WHERE

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.

like image 653
2b77bee6-5445-4c77-b1eb-4df3e5 Avatar asked Jul 16 '14 15:07

2b77bee6-5445-4c77-b1eb-4df3e5


People also ask

Can we use multiple conditions in WHERE clause in SQL?

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 you do multiple sets in SQL UPDATE?

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.

What does WHERE 1 do in SQL?

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.

Can WHERE clause have multiple values?

The IN operator allows you to specify multiple values in a WHERE clause. The IN operator is a shorthand for multiple OR conditions.


1 Answers

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.

like image 153
Matas Vaitkevicius Avatar answered Oct 07 '22 22:10

Matas Vaitkevicius