在表中插入新行,但从表中的另一行复制数据

时间:2016-10-03 09:05:41

标签: sql ingres

我的ingres db中有一个表,其中包含以下值,例如

grd    gsd    Name   Location
112    04     Joe    Test

我想创建一个新行,复制相同的数据但是" grd"值更改为新值,如下所示

grd    gsd    Name   Location
113    04     Joe    Test

如何在优化的sql语句中实现此目的?

2 个答案:

答案 0 :(得分:2)

尝试这样的事情:

INSERT INTO your_table (grd, gsd, Name, Location)
    SELECT
        grd,--or change it here as you need (for example replacing with value 113)
        gsd,
        Name,
        Location
    FROM your_table
    --WHERE some condition (e.g. grd = 112)

答案 1 :(得分:-1)

insert into MyTable(field1, field2, "113")
select field1, field2, grd from MyTable where grd = "112";