Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI i try to run this code
INSERT INTO OpenOrder 
SELECT OpenOrderTemp.*
FROM OpenOrderTemp
LEFT OUTER JOIN OpenOrder OpenOrder ON  OpenOrder.Symbol=OpenOrderTemp.Symbol 
                                    and OpenOrder.orderId=OpenOrderTemp.orderId  
                                    and OpenOrder.orderListId=OpenOrderTemp.orderListId;

and is worked first time after i erase a update and try again to rerun a code but the second time it return me error,
Duplicate entry '1' for key 'OpenOrder.PRIMARY'

why ?? i erase a uploded o_O

 here my openordertemp table
<a href="https://ibb.co/ZXmSmgt">oredertemp — ImgBB[^]</a>[<a href="https://ibb.co/ZXmSmgt" target="_blank" title="New Window">^</a>]


and here my openorder
<a href="https://ibb.co/DrRz5dn">openorder — ImgBB[^]
[^]

What I have tried:

i tryed also to reset altertable
Posted
Updated 11-Jul-22 3:01am
v3

Primary key values cannot be duplicated: you cannot insert a second row to the same able with an identical primary key value.

Check what the temporary table contains, and compare that against your OpenOrder table.

Then you can work out why it's a duplicate - but we can't as we have no access at all to your data!
 
Share this answer
 
I showed you how to do this on your earlier question. You need to include the WHERE clause from that solution i.e.
SQL
INSERT INTO OpenOrder 
SELECT OpenOrderTemp.*
FROM OpenOrderTemp
LEFT OUTER JOIN OpenOrder OpenOrder ON  OpenOrder.Symbol=OpenOrderTemp.Symbol 
                                    and OpenOrder.orderId=OpenOrderTemp.orderId  
                                    and OpenOrder.orderListId=OpenOrderTemp.orderListId
WHERE OpenOrder.Symbol IS NULL
Without that clause you are attempting to insert keys 1 and 2 - but they already existing in OpenOrder.

Please take care to read solutions carefully and understand what is happening with your code, you cannot just pick and choose which lines of the advice to follow and expect everything to still work.
 
Share this answer
 
Comments
[no name] 12-Jul-22 5:35am    
thanks , but also with where WHERE OpenOrder.Symbol IS NULL , return me Duplicate entry '1' for key 'OpenOrder.PRIMARY'
CHill60 12-Jul-22 11:52am    
Not with the sample data you shared on those links and not with the code in my solution it doesn't.
SQL Fiddle[^]

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