Results 1 to 5 of 5

Thread: Query Help

  1. #1
    Join Date
    Jun 2011
    Posts
    2

    Query Help

    I have this query:

    INSERT INTO tblPartColors ( PartID, ColorID )
    SELECT DISTINCT tblParts.PartID, tblColors.ColorID
    FROM (tblParts INNER JOIN tbl_PartsList_Import ON tblParts.PartNum = tbl_PartsList_Import.PartNum) INNER JOIN tblColors ON tbl_PartsList_Import.ColorName = tblColors.ColorName;

    Which allows me to import/append tblPartColors with unique combinations of PartID and ColorID.

    However, if I run the query a second time against the same data, I get duplicates in my tblPartColors. Is there anyway to do a comparative append query, which won't allow duplicate PartID, ColorID combinations?

  2. #2
    Join Date
    Oct 2006
    Location
    Maitland NSW Australia
    Posts
    275
    In your table tblPartColors set your Primary Key to PartID+ColorID.
    Allan

  3. #3
    Join Date
    Jun 2011
    Posts
    2
    I didn't know you could set 2 fields as a single primary key

  4. #4
    Join Date
    Oct 2006
    Location
    Maitland NSW Australia
    Posts
    275
    Yes, you can set multiple fields as a primary key. The number of fields in a primary key depend on your table structure etc.
    Allan

  5. #5
    Join Date
    Mar 2006
    Location
    Oklahoma City, OK
    Posts
    184
    While it is possible to do I have never had to do it. It has many issues. There has been many debates on whether you should ever do it. I have never found a good reason to do it so far in 30+ years and 000's of databases.

    I will make a compound index using multiple fields set to no dups.
    Boyd Trimmell aka HiTech Coach
    Microsoft MVP - Access Expert
    [SIGPIC][/SIGPIC]
    Office Programming 25+ years as a Software Developer specializing in:
    Business Process Management
    Accounting/Inventory Control
    Customer Relations Management (CRM)
    Electronic Data Interchange (EDI)

Posting Permissions

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