![](/img/trans.png)
[英]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.