Hướng dẫn update replace mysql
13.2.13 UPDATE Statement An Single-table syntax:
Multiple-table syntax:
For the single-table syntax, the For the multiple-table syntax,
For partitioned tables, both the single-single and multiple-table forms of this statement support the use of a Note Unlike the case when using For more information and examples, see Section 24.5, “Partition Selection”. You need the The
If you access a column from the table to be updated in an expression,
The second assignment in the following statement sets
Single-table If you set a column to the value it currently has, MySQL notices this and does not update it. If you update a column that has been declared If a generated column is updated explicitly, the only permitted value is
You can use If an
For example, if the table contains 1 and 2 in the
You can also perform
The
preceding example shows an inner join that uses the comma operator, but multiple-table If you use a multiple-table
You cannot update a table and select directly from the same table in a subquery. You can work around this by using a multi-table update in which one of the tables is derived from the table that you actually wish to update, and referring to the derived table using an alias. Suppose
you wish to update a table named
To reduce the retail price of any items for which the markup is 30% or greater and of which you have fewer than one hundred in stock, you might try to use an
Instead, you can employ a multi-table update in which the subquery is moved into the
list of tables to be updated, using an alias to reference it in the outermost
Because the optimizer tries by default to merge the derived table
The advantage of using the optimizer hint in such a case is that it applies only within
the query block where it is used, so that it is not necessary to change the value of Another possibility is to rewrite the subquery so that it does not use
In this case, the subquery is materialized by default rather than merged, so it is not necessary to disable merging of the derived table. |