views:

31

answers:

3

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
tried this query but when execute again duplicate rows created
shanks
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
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
table structure is UsrID UserName Date Time
shanks
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
A: 

INSERT INTO "table1" ("column1", "column2", ...)
SELECT "column3", "column4", ...
FROM "table2"
minus
SELECT "column1", "column2", ...
FROM "table1"

Randy