Get the App
SLTechnology News&Howtos  ›  Database  › 

The method of updating multiple fields at the same time using sql

Shulou Source: shulou.com Published: 2022-06-01 04:31:05 10月02日 Update

This article will explain in detail how to use sql to update multiple fields at the same time. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

In SQL, update statement is used to update data, while SQL uses update statement to update multiple field statements at a time in many ways. Here are two ways to introduce you. I hope it will be helpful to you.

Method 1:

UPDATE table name SET field 1 = value, field 2 = value 2. [WHERE condition]

Multiple fields can be separated by commas. Each "field name = value" assigns a value to the field, and subsequent WHERE conditional statements can be used or not.

Note: the conditions after set cannot be used with commas. The conditions after and,set are not associated with each other and cannot be associated with each other, so and cannot be used; where conditions can be followed by and.

Example:

Update table set sex= 'male', name=' Zhang San 'where id = 1; / correct update table set sex=' male 'and name=' Zhang San' where id = 1; / / error

Method 2:

Update table name set (field 1, field 2, field 3) = (select numeric 1, numeric 2, numeric 3 from table name where....) Where conditions on the use of sql to update multiple fields at the same time to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Fields conditions multiple methods updates statements numeric values at the same time more articles commas Zhang San associations help good practical no between content multiple Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MySQL OPPO Reno Huawei macOS