How to add data from one table to another table with new data in sql
+1
A:
You'd use an SQL INSERT INTO SELECT like so:
INSERT INTO "table1" ("column1", "column2", ...)
SELECT "column3", "column4", ...
FROM "table2"
You can find more info here: http://www.1keydata.com/sql/sqlinsert.html
lomaxx
2010-04-17 14:32:49
tried this query but when execute again duplicate rows created
shanks
2010-04-17 14:34:49
Yes, if you execute the same query, with hardcoded values, you will get the same record inserted. If you want a better answer then you need to provide more information.
MJB
2010-04-17 14:37:46
A:
Don't have enough points to comment, but lomaxx's query is functioning correctly @shanks. If you run an insert query again, you will get duplicates for each time the query is run.
Braintapper
2010-04-17 14:37:45
I think you need to clarify your question. Sounds like you want to insert _new_ records from another table. That's a whole different answer.
Braintapper
2010-04-17 15:10:17
A:
INSERT INTO "table1" ("column1", "column2", ...)
SELECT "column3", "column4", ...
FROM "table2"
minus
SELECT "column1", "column2", ...
FROM "table1"
Randy
2010-04-17 22:54:14