Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Posts
    139

    Unanswered: Selecting a distinct row query

    I am trying to append data from a source table to a destination table, the only difference between the tables is that a primary key has been established on the destination table. Problem is, the source table has a handful of duplicate values in the column that corresponds to primary on destination table; so when I run the query I get a primary key conflict. What I'd like to do is select distinct values from the source table to avoid the conflict, but am having trouble getting it to run. Here is the statement-

    INSERT INTO cust_master
    SELECT DISTINCT cust_master_temp.*
    FROM cust_mast_temp LEFT OUTER JOIN
    cust_master ON cust_master.temp.CUST_NUMBER = cust_master.CUST_NUMBER

    Doesn't seem to be understanding "Distinct"

    Any Ideas?
    Thanks,
    Bill

  2. #2
    Join Date
    Oct 2003
    Posts
    84
    if you don't want to insert the rows that have a primary key value
    that is already present in the destination table:

    INSERT INTO cust_master
    SELECT * FROM cust_master_temp
    WHERE cust_number NOT IN
    (SELECT cust_number FROM cust_master)

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I think you need to add:

    WHERE cust_master.CUST_NUMBER IS NULL

    to your SELECT statement. That will pull only the rows that are NOT already in cust_master, instead of only the rows that are already IN cust_master.

    -PatP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •