Skip to content
Advertisement

set data from a table in itself

So, i have to migrate some data, the query is:

SELECT * FROM ldf.vin_EntePublicoLDF WHERE ejr_id = 2019;

and i have to take those data but set “2020” I try with:

SET vin_EntePublicoLDF.ejr_id = 2020
INSERT INTO ldf.vin_EntePublicoLDF
SELECT * FROM ldf.vin_EntePublicoLDF WHERE vin_EntePublicoLDF.ejr_id = 2019;`

But i recive an error:

[Err] 1193 – Unknown system variable ‘ejr_id’

Any suggestion ?

Advertisement

Answer

If you are trying to update the data, use update:

update ldf.vin_EntePublicoLDF 
    set ejr_id = 2020
    where ejr_id = 2019;

If you want to insert new rows:

INSERT INTO ldf.vin_EntePublicoLDF ( . . ., ejr_id )  -- list columns here
    SELECT . . ., 2020
    FROM ldf.vin_EntePublicoLDF
    WHERE ejr_id = 2019;
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement