MySQL select results to perform update example tutorial

MySQL select results to perform update example tutorial

1. Single table query -> update

UPDATE table_name
SET field1=new-value1, field2=new-value2
[WHERE Clause]

2. Multi-table joint query -> update

UPDATE a
INNER JOIN (SELECT yy FROM b) c ON a.id = c.id 
SET a.xx = c.yy
[WHERE Clause]
  • The above INNER JOIN can be replaced by LEFT JOIN, RIGHT JOIN and other joint queries.
  • The field after SET must be a field in table a. The field can be equal to a constant or a column. If it is not a field in table a, the message "The target table b of the UPDATE is not updatable" will be reported.
  • The WHERE clause must be placed after SET
  • The a table after UPDATE is not the result of a query, nor can it be a SELECT clause.

example:

tableex_copy1 table

tablein_copy1 table

Query SQL

SELECT * FROM
tableex_copy1 a LEFT JOIN
(SELECT * FROM tablein_copy1) b
ON a.BID = b.AID
WHERE b.ASEX = 'female'

update SQL

UPDATE
#SELECT * FROM
tableex_copy1 a LEFT JOIN
(SELECT * FROM tablein_copy1) b
ON a.BID = b.AID
SET a.CESHI = '6666'
WHERE b.ASEX = 'female'

Tableex_copy1 table after update

Summarize

This is the end of this article about MySQL executing update on select results. For more relevant content about MySQL executing update on select results, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • A brief discussion on MySQL select optimization solution
  • Solve the problem that MySQL read-write separation causes data not to be selected after insert
  • How MySQL Select Statement is Executed
  • Detailed example of using the distinct method in MySQL
  • Should I use distinct or group by to remove duplicates in MySQL?
  • The difference between distinct and group by in MySQL
  • Let's talk about the LIMIT statement in MySQL in detail
  • MySQL series tutorial on understanding the use of union (all) and limit and exists keywords
  • The impact of limit on query performance in MySQL
  • Use of select, distinct, and limit in MySQL

<<:  HTML table tag tutorial (17): table title vertical alignment attribute VALIGN

>>:  Front-end state management (Part 2)

Recommend

Linux uses iftop to monitor network card traffic in real time

Linux uses iftop to monitor the traffic of the ne...

dl, dt, dd list label examples

The dd and dt tags are used for lists. We usually...

jQuery achieves seamless scrolling of tables

This article example shares the specific code of ...

Ubuntu compiles kernel modules, and the content is reflected in the system log

Table of contents 1.Linux login interface 2. Writ...

Discussion on the Issues of Image Button Submission and Form Repeated Submission

In many cases, in order to beautify the form, the ...

js to achieve cool fireworks effect

This article shares the specific code for using j...

Detailed explanation of asynchronous programming knowledge points in nodejs

Introduction Because JavaScript is single-threade...

Detailed steps to install Mysql5.7.19 using yum on Centos7

There is no mysql by default in the yum source of...

Two methods of implementing automatic paging in Vue page printing

This article example shares the specific code of ...

Summary of commonly used SQL statements for creating MySQL tables

Recently, I have been working on a project and ne...

Simple tutorial on using Navicat For MySQL

recommend: Navicat for MySQL 15 Registration and ...

VUE implements token login verification

This article example shares the specific code of ...

Implementation of CentOS8.0 network configuration

1. Differences in network configuration between C...

Implementing form submission without refreshing the page based on HTML

Using ajax to implement form submission without re...

MySQL 8.0.21 free installation version configuration method graphic tutorial

Six steps to install MySQL (only the installation...