Question : Inserting unique records from another table

I have a table called trackingInfo with a unique constraint of the two fields:
Tracking, Ship_Date.

I also have a table called trackingInfo_scratch with the same fields but without any contraints (duplicates are allowed)

I want to insert records into trackingInfo from trackingInfo_scratch, but only the first unique combination of Tracking and Ship_Date.

In my query below I still get the standard contraint error in SQL Server. What am I doing wrong?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
INSERT INTO trackingInfo(
  trackingInfo.Shipper,
  trackingInfo.Main_Acct,
  trackingInfo.Tracking,
  trackingInfo.Pickup_Date,
  trackingInfo.Ship_Date)
SELECT
  trackingInfo_scratch.Shipper,
  trackingInfo_scratch.Main_Acct,
  trackingInfo_scratch.Tracking,
  trackingInfo_scratch.Pickup_Date,
  trackingInfo_scratch.Ship_Date,
FROM       trackingInfo_scratch
 WHERE NOT EXISTS
     (SELECT trackingInfo.Tracking, trackingInfo.Ship_Date
           FROM trackingInfo
           WHERE trackingInfo.Tracking = trackingInfo_scratch.Tracking and
                 trackingInfo.Ship_Date = trackingInfo_scratch.Ship_Date)
Open in New Window Select All

Answer : Inserting unique records from another table

use distinct keyword.

INSERT INTO trackingInfo(
  trackingInfo.Shipper,
  trackingInfo.Main_Acct,
  trackingInfo.Tracking,
  trackingInfo.Pickup_Date,
  trackingInfo.Ship_Date)
SELECT distinct
  trackingInfo_scratch.Shipper,
  trackingInfo_scratch.Main_Acct,
  trackingInfo_scratch.Tracking,
  trackingInfo_scratch.Pickup_Date,
  trackingInfo_scratch.Ship_Date,
FROM       trackingInfo_scratch
 WHERE NOT EXISTS
     (SELECT trackingInfo.Tracking, trackingInfo.Ship_Date
           FROM trackingInfo
           WHERE trackingInfo.Tracking = trackingInfo_scratch.Tracking and
                 trackingInfo.Ship_Date = trackingInfo_scratch.Ship_Date)
Random Solutions  
 
programming4us programming4us