Home > Database > SQL > How to update one table with another table through SQL statement

How to update one table with another table through SQL statement

王林
Release: 2020-07-07 11:50:42
Original
14740 people have browsed it

How to update one table with another table through SQL statements: You can use the SELECT INTO statement. For example, [update visit set visit.nm = user.nm from user where visit.uid = user.uid].

How to update one table with another table through SQL statement

#If you want to insert data from one table into another table, you can use the SELECT INTO statement or INSERT INTO SELECT statement.

(Recommended learning: mysql tutorial)

Example:

Now there are the following two tables:

User information table users

How to update one table with another table through SQL statement

Historical information table visit

How to update one table with another table through SQL statementUpdate sql statement

update visit
set visit.username = users.username, visit.phone = users.phone
from users
where visit.uid = users.uid
Copy after login

Update result:

Historical information table visit

vid	uid	time	               username	phone
1	1	2019/06/15 19:23:45	Tom	13966666666
2	2	2019/06/18 14:03:59		
3	3	2019/06/23 07:45:21	Lucy	13999999999
Copy after login

The above is the detailed content of How to update one table with another table through SQL statement. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template