Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am inserting data into table from another table, But I am getting duplicates.
Any body give me where I need to add delete query.

SQL
Insert into tb2(fields)
select * from tb1;


So above query where I need to add delete query for deleting duplicate records.

sol:
Posted
Updated 26-Nov-13 23:29pm
v5

1 solution

You need to use subquery as is described in this article: Oracle SQL subquery types in, not in, exists[^].
Example:
SQL
Insert into tb2(Field1, Field2)
SELECT Field1, Field2
FROM tb1
WHERE NOT EXISTS (SELECT Field1 FROM tb1) ;
 
Share this answer
 
Comments
Maciej Los 27-Nov-13 5:29am    
Please, read my answer? Do i recommend you to delete data? No!
phil.o 27-Nov-13 6:11am    
5'd :)
Maciej Los 27-Nov-13 6:19am    
Thank you, Phil ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900