mysql 從乙個表中查資料,插入另乙個表

2021-07-16 02:38:25 字數 428 閱讀 5283

類別一、 如果兩張張表(匯出表和目標表)的字段一致,並且希望插入全部資料,可以用這種方法:

insert into

目標表select  * from

**表 ;

例如,要將 articles 表插入到 newarticles 表中,則可以通過如下sql語句實現:

insert into

newarticles

select  * from

articles ;

類別二、 如果只希望匯入指定字段,可以用這種方法:

insert into

目標表 (欄位1, 欄位2, ...)

select

欄位1, 欄位2, ...

from

**表 ;

請注意以上兩表的字段必須一致,否則會出現資料轉換錯誤。

mysql 從乙個表中查資料並插入另乙個表實現方法

mysql 從乙個表中查資料並插入另乙個表實現方法 不管是在 開發還是在應用程式開發中,我們經常會碰到需要將mysql或ms sqlserver某個表的資料批量匯入到另乙個表的情況,甚至有時還需要指定匯入字段。本文就將以mysql資料庫為例,介紹如何通過sql命令行將某個表的所有資料或指定欄位的資料...

mysql 從乙個表中查資料並插入另乙個表實現方法

類別一 如果兩張張表 匯出表和目標表 的字段一致,並且希望插入全部資料,可以用這種方法 insert into 目標表 select from 表 例如,要將 articles 表插入到 newarticles 表中,則可以通過如下sql語句實現 insert into newarticles se...

mysql從乙個表中查詢資料插入到另乙個表中

insert into table1 select from table2 insert into table1 field1 select field1 from table2 注意 select之後的字段如果大於乙個,不能用括號括起來,否則,系統會報錯 operand should contai...