I needed to write a SQL command that will populate a new column that has just been introduced into a table but spent quite some time figuring how to do that using the INSERT INTO SQL statement. Instead of thinking about INSERT INTO, what was needed in this scenario is the UPDATE syntax.
Insert new rows. Can also do updates if a unique key duplicate has been found and thus can be updated through:
INSERT INTO tablename ON DUPLICATE KEY UPDATE columnName1='newValue1', columnName2='newValue2'...
To update pre-existing rows. Exampl:
UPDATE tablename set columnName = 'newValue'
Leave a Reply