關於 MYSQL COPY TABLE Command

2010-03-30 10:14 pm
關於 MYSQL COPY TABLE Command
怎樣把 MYSQL 資料庫ABC的 TABLE:ONE, TABLE:TWO, TABLE:THREE, COPY TO 資料庫ABC的 TABLE:TOTAL.
thank a lot
easy9756

回答 (1)

2010-03-30 11:13 pm
✔ 最佳答案
if "TOTAL" is a existing table and u want to insert all records from tables "ONE", "TWO", "THREE".  u can use following SQL.

INSERT into total ( cost_centre, id, name )
SELECT cost_centre, id, name FROM one 
UNION ALL
SELECT cost_centre, id, name FROM two 
UNION ALL 
SELECT cost_centre, id, name FROM three.


If "TOTAL" isn't a existing table and u need to create it and to insert all records from tables "ONE", "TWO", "THREE".  u can use following SQL.

CREATE TABLE total AS
SELECT cost_centre, id, name FROM one 
UNION ALL
SELECT cost_centre, id, name FROM two
UNION ALL 
SELECT cost_centre, id, name FROM three.



收錄日期: 2021-04-13 17:11:07
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20100330000051KK02576

檢視 Wayback Machine 備份