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].
#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
Historical information table visit
Update sql statement
update visit set visit.username = users.username, visit.phone = users.phone from users where visit.uid = users.uid
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
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!