[英]Transferring data from one table to another using a where clause mysql
[英]MySql: Copy data from one table to another with WHERE clause
我想将数据从一个表复制到另一个表。
我想复制一些数据,比如说:“安迪”。 他的数字为“ 5”,其数据为“酷”。
这存储在表1中。
现在,我想将数据“ cool”插入表2中,其中数字为“ 5”。
的SQL
INSERT TO table2 SET data = (SELECT data FROM table1 WHERE number = table2.number)
因此,这应该像循环一样从多个用户复制数据。
我应该怎么做?
如果需要从Table1的值更新Table2的值,则可以将update语句与联接一起使用。
UPDATE Table2
JOIN Table1 ON Table1.number = Table2.number
SET Table2.data = Table1.data;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.