Results 1 to 5 of 5
  1. #1
    raynman1972 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    31

    Need to insert 4 columns into a table, but only if they don't already exist

    I have two tables that have 5 columns in common, but there are rows missing from one that are present in the other. Can I use "WHERE NOT EXISTS", or something similair, that can select these rows from table A that are missing from table b so that I can insert them? As some background, one table is based off of forecasted data and the other is based off of actuals and the delta is that there are some intervals where, despite there being a forecast, there are no actuals.



    Code:
    SELECT 
     DAT_WWCP_STF_DATA.SITE
    ,DAT_WWCP_STF_DATA.FCST_GROUP
    ,DAT_WWCP_STF_DATA.INTERVAL AS ARRIVAL_INTERVAL
    ,DAT_WWCP_STF_DATA.DATE AS ARRIVAL_DATE
    ,DAT_WWCP_STF_DATA.FORECAST
    
    FROM DAT_WWCP_STF_DATA
    
    WHERE NOT EXISTS
    (
    SELECT
     EMAILS_RESOLVED_SUMMARY.SITE
    ,EMAILS_RESOLVED_SUMMARY.FCST_GROUP
    ,EMAILS_RESOLVED_SUMMARY.ARRIVAL_INTERVAL
    ,EMAILS_RESOLVED_SUMMARY.ARRIVAL_DATE
    ,EMAILS_RESOLVED_SUMMARY.FORECAST
    
    FROM EMAILS_RESOLVED_SUMMARY
    );

  2. #2
    TheShabz is offline Court Jester
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    1,368
    is there a common unique field between the two tables?

  3. #3
    raynman1972 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    31
    Unfortunately, no.

  4. #4
    TheShabz is offline Court Jester
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    1,368
    Ok. Are you looking for exact duplicates? If so, you can just append to the table, then do
    SELECT (every field without using *)
    INTO (New table name)
    FROM (The table)
    GROUP BY (every field)

    Which will remove every exact duplicate record, leaving you with one.

    You can then delete the old table (make a backup first to make sure it all works correctly) and rename the new one. It's pretty kludgy but if you have no identifying field, you don't have many options.

  5. #5
    raynman1972 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    31
    Yeah, I think that would do it. I agree that this would not be a very elegant solution and I have not found anything else for alternative. Thanks for your time and reply

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 03-14-2012, 06:48 AM
  2. Checking if data already exist in a Table
    By Phillsoft in forum Forms
    Replies: 2
    Last Post: 08-04-2011, 02:07 PM
  3. Checking if data already exist in a Table
    By Phillsoft in forum Forms
    Replies: 1
    Last Post: 08-04-2011, 08:03 AM
  4. If value already exist or not in the table
    By dada in forum Programming
    Replies: 3
    Last Post: 08-19-2010, 01:57 AM
  5. Check if value exist in a table
    By Lucas83 in forum Programming
    Replies: 2
    Last Post: 06-02-2010, 11:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums