从同一个表中插入表数据

时间:2014-10-19 16:13:25

标签: sql

我有一个表需要更新,基本上是重复数据,除了一列数据。

我的表名是tblSupporters

我的专栏是

ID, SYear, Type, Support Location, City, State, Info.

我需要复制SYear等于2012的表格中的数据并插入同一个表格,但将SYear更改为2013。

我知道这很简单,但我对此很陌生。

1 个答案:

答案 0 :(得分:3)

只需使用insert . . . select

insert into tblSupporters(ID, SYear, Type, Support Location, City, State, Info)
    select ID, 2013 as SYear, Type, Support Location, City, State, Info
    from tblSupporters
    where SYear = 2012;

我的猜测是id会自动分配,因此您可能真的需要:

insert into tblSupporters(SYear, Type, Support Location, City, State, Info)
    select 2013 as SYear, Type, Support Location, City, State, Info
    from tblSupporters
    where SYear = 2012;