Sunday, February 26, 2012

SQL transfer data from one table to another...

<< for tables with exact same columns only >>

//creating new table
SELECT *
INTO new_table
FROM old_table
WHERE condition


// with existing table
INSERT new_table SELECT * FROM old_table

<< for transfer with static value and/or tables with NOT exact same columns only >>

INSERT INTO new_table (columns, columns, columns)
SELECT columns, sum(), static_value FROM old_table

WHERE condition

No comments: