Discover how to update multiple rows in sql, include the articles, news, trends, analysis and practical advice about how to update multiple rows in sql on alibabacloud.com
the data is updated, and the WHERE clause ensures that only 3 rows of data are executed.
If you update multiple values, you need to modify them only slightly:
The code is as follows
UPDATE Categories
SET Display_order = case ID
When 1 THEN 3
When 2 THEN 4
When 3 THEN 5
1 THEN 'value'WHEN 2 THEN 'value'WHEN 3 THEN 'value'ENDWHERE id IN (1, 2, 3)
Here we use the case when tip to implement batch update.For example:
Copy codeThe Code is as follows:UPDATE categoriesSET display_order = CASE idWHEN 1 THEN 3WHEN 2 THEN 4WHEN 3 THEN 5ENDWHERE id IN (1, 2, 3)
This SQL statement indicates that the display_order field is updated. If id = 1, the value of display_order is 3. If id = 2, the value of display_order is 4, if id = 3,
This article illustrates the way Android implements SQLite Add, update, and delete rows. Share to everyone for your reference, specific as follows:
The Sqlitedatabase class exposes specific methods, such as inserts, deletes, and updates, which wrap the SQL statements required to perform these actions. However, the Execsql method allows you to execute any valid
How to efficiently split a field into multiple rows I originally split a field in the table into multiple rows, such as aaa and bbb into aaabbb. Now the test is as follows: [SQL] witht1as (select3c1, eee, fff, gggc2fromdualUNIONALLselect2c1, ccc, dddc2fromdualUNIONALLSELECT1
The following is a test example.1. Create two temporary tables and input test data:Copy codeThe Code is as follows:Create table # temptest1(Id int,Name1 varchar (50 ),Age int)Create table # temptest2(Id int,Name1 varchar (50 ),Age int)
The following table data is queried:
# Temptest1 # temptest2
2. Now we need to update the age in # temptest2 to the corresponding age in # temptest1.
In fact, the age of ID 1 in [Table 1] is changed to 19, and the ag
The following is a test example.
1. First create two temporary tables and input test data:
Copy Code code as follows:
CREATE TABLE #temptest1
(
ID int,
name1 varchar (50),
Age int
)
CREATE TABLE #temptest2
(
ID int,
name1 varchar (50),
Age int
)
The table data at this point in the query is:
#temptest1 #temptest2
2. It is now time to update the age in the #temptest2 to the corresponding #temptest1.
error occurs: "The modified or deleted row value cannot be changed to a unique row, or multiple rows (X rows) have been changed.
It turns out that I forgot to add the primary key when creating the table, but now I cannot delete it. I can enter something in it, but I cannot enter it, and an error is returned. No way ~ Baidu ~ Various solutions finally found the
Normally, we use SQL to execute INSERTINTO 'tabale '('name') VALUE (name). If php needs to execute such SQL statements cyclically, therefore, execute an SQL statement below to insert multiple rows of records. INSERTINTO 'tabale '('name') VALUE (name), (name) How many pieces
by Field 1, Field 2, Field 3 having COUNT (*) > 1)
Where: Field 1, Field 2, Field 3 refers to the three fields that need to establish a unique constraint, selfid refers to one of the self-increment fields in tables table.
2. Delete duplicate records and keep only the Selfid minimum records, that is, the first inserted records:[SQL]View Plaincopy
DELETE from dbo. Tablesign
WHERE Selfid in
(SELECT Selfid from dbo. ) T
Mysql uses group_concat () to merge multiple rows of data into one row, and mysqlgroup_concat
Assume that two tables a, B, and B are associated with table a through the field id, and table a and table B are one-to-many relationships. Assume that table B has a field name. Now you need to query the records in Table a and obtain the name information stored in Table B according to the regular query, the number
Why can't foreach retrieve only one row when using the mysqli class, while loop fetch multiple rows of data? I am a newbie. if you have any questions, please use the mysqli class. the data table test contains five rows of data. The foreach function can only retrieve the first row. None of the other rows can be retrieve
variables, individually, according to the conditions. The solution to this problem now is to embed the SQL language into the Advanced programming language, the use of advanced programming language to deal with the advantages of strong data, and SQL language to the database direct operation of the characteristics of the joint completion, this to a certain extent, both to increase the difficulty of writing p
Tags: active mod field name SQL statement. com ALT module Name is youA field may correspond to multiple data, and a MySQL implementation combines multiple rows of data into one row of data For example, an activity ID (Activeid) corresponds to multiple module names (modelname
all the routes To implement each point string grouped by flt,seg and sorted by srtsum, the writable SQL is Select Flt,seg,tran_level, Wmsys. Wm_concat (name) over (PARTITION by flt,seg ORDER by Srtnum) KEY From Flight_tran_direction where seg>0 ORDER BY Flt,seg The result: similar to group by FLT,SEG, the grouping by FLT,SEG is implemented, and name is sorted by Srtnum logic. The only disadvantage is that a group will have several more historical
Merge the multi-row records obtained by querying the name field, which can be implemented through a program, but can also be completed directly at the SQL layer. For more information, see the following two tables a, B, table B is associated with table a through the field id, and table a and Table B are one-to-many relationships. Assume that Table B has a field name. now you need to query the records in Table a and obtain the name information stored in
How does one Delete multiple rows of the same data in the same table but retain one? Delete a table with multiple rows of the same data, but keep one row of data, as shown in the following table:ID name cdefine1 cdefine2 cdefine3
1 aa 101 09-08
2 AA 101 09-09
3 BB 101 09-09
4 cc 204 09-12
5 cc 204 09-13
6 dd 255 09-05
After the oracle splits the string, it is displayed in a single column and multiple rows in oracle.
Original SQL:
Select substr (field1, instr (field1, '|', 1, rownum) + 1, instr (field1, '|', 1, rownum + 1)-instr (field1, '|', 1, rownum)-1) as field2 from (select '| 'a | bbb | cccc | ddddd | ee | d | a' |' as field1 from dual) connect by instr (field1, '|', 2,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.