Search code examples
sqlingres

Insert new rows into table but copy data from another row in the table


I have a table within my ingres db with the following values for example

grd    gsd    Name   Location
112    04     Joe    Test

I want to create a new row with the same data copied but the "grd" value changed to a new value like below

grd    gsd    Name   Location
113    04     Joe    Test

How can I achieve this in an optimised sql statement?


Solution

  • Try something like this:

    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)