Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poudelmadhav/aef3fea88a1084339bfcf60f313ad585 to your computer and use it in GitHub Desktop.
Save poudelmadhav/aef3fea88a1084339bfcf60f313ad585 to your computer and use it in GitHub Desktop.
Copy one data from another table SQL

Copy data from one table to another table, and insert it.

INSERT INTO destination_table(
  col1, col2, col3, col4, col5, col6
)
SELECT col1, col2, col3, 'custom_value' as col4, col5, col6
FROM source_table;

Copy data from one table and update with having same id and conditions

UPDATE destination_table
SET
  col1 = source_table.col1,
  col2 = source_table.col2
FROM source_table
WHERE destination_table.col1 = source_table.col1
AND source_table.col2 = 'this is cool'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment