SQL 教程
通過(guò) SQL,您可以從一個(gè)表復(fù)制信息到另一個(gè)表。
INSERT INTO SELECT 語(yǔ)句從一個(gè)表復(fù)制數(shù)據(jù),然后把數(shù)據(jù)插入到一個(gè)已存在的表中。
INSERT INTO SELECT 語(yǔ)句從一個(gè)表復(fù)制數(shù)據(jù),然后把數(shù)據(jù)插入到一個(gè)已存在的表中。目標(biāo)表中任何已存在的行都不會(huì)受影響。
我們可以從一個(gè)表中復(fù)制所有的列插入到另一個(gè)已存在的表中:
或者我們可以只復(fù)制希望的列插入到另一個(gè)已存在的表中:
在本教程中,我們將使用 JSON 樣本數(shù)據(jù)庫(kù)。
下面是選自 "Websites" 表的數(shù)據(jù):
+----+--------------+---------------------------+-------+---------+ | id | name | url | alexa | country | +----+--------------+---------------------------+-------+---------+ | 1 | Google | https://www.google.cm/ | 1 | USA | | 2 | 淘寶 | https://www.taobao.com/ | 13 | CN | | 3 | 小白教程 | http://www.9t9t.com.cn | 888 | CN | | 4 | 微博 | http://weibo.com/ | 20 | CN | | 5 | Facebook | https://www.facebook.com/ | 3 | USA | | 7 | stackoverflow | http://stackoverflow.com/ | 0 | IND | +----+---------------+---------------------------+-------+---------+
下面是 "apps" APP 的數(shù)據(jù):
mysql> SELECT * FROM apps; +----+------------+-------------------------+---------+ | id | app_name | url | country | +----+------------+-------------------------+---------+ | 1 | QQ APP | http://im.qq.com/ | CN | | 2 | 微博 APP | http://weibo.com/ | CN | | 3 | 淘寶 APP | https://www.taobao.com/ | CN | +----+------------+-------------------------+---------+ 3 rows in set (0.00 sec)
復(fù)制 "apps" 中的數(shù)據(jù)插入到 "Websites" 中:
只復(fù) QQ 的 APP 到 "Websites" 中: