[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem with Code

Posted on 2005-05-03
6
Medium Priority
?
220 Views
Last Modified: 2010-03-19
Hi
Can anyone tell me why this will not work correctly

insert into(Table1
columns)
(select table2
columns
from table2
where tabel2.pageURL not in (select table1.pageURL from table1))

I keep getting an error saying cannot insert duplicate records due to key violation

Any help would be appreciated
Caz
0
Comment
Question by:BeginningWebDesign
6 Comments
 
LVL 13

Accepted Solution

by:
ispaleny earned 2000 total points
ID: 13916507
in table Table1 ýou have primary or unique key to ensure uniqueness. table table2
 doesn't meet these requirements, there are duplicities.
0
 
LVL 13

Expert Comment

by:ispaleny
ID: 13916516
Post DDL definition of your tables Table1 and Table2, then I am able to help you more.
0
 
LVL 10

Expert Comment

by:PSSUser
ID: 13917066
You could try:

insert into(Table1
columns)
(select DISTINCT table2
columns
from table2
where tabel2.pageURL not in (select table1.pageURL from table1))
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
LVL 34

Expert Comment

by:Brian Crowe
ID: 13917901
This should only insert the records that don't already exist in Table1 if you join on the key column(s).  It would help if like ispaleny said you posted your table schema.

INSERT INTO Table1 (...columns...)
SELECT Table2.col1, Table2.col2, ...
FROM Table2
LEFT OUTER JOIN Table1
     ON {key columns}
WHERE Table1.col1 IS NULL
0
 

Expert Comment

by:jawad_ashraf
ID: 13918689
it will work

insert into(Table1
columns)
(select distinct table2
columns
from table2
where tabel2.pageURL not in (select distinct table1.pageURL from table1))

jawad

0
 

Author Comment

by:BeginningWebDesign
ID: 13920820
Sorry ispaleny for taking so long to get back computer was down, you where right there was dup's in table 2 that was causing the problem

Caz
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question