Results 1 to 11 of 11
  1. #1
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283

    Query to find unmatch data between two tables


    Hello,

    I have two tables: PVE and TEST_EEAF.
    PVE has around 220 fields and TEST_EEAF has around 140. They both have the same PK which is HICN. And they also both have some of the same fields on each table. I'm trying to write a query that will display all the rows with unmatched data between the two tables and show the field names. And if there are no unmatched rows show a message saying everything is matched. Thank you

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Can't have 'message' in the query. If everything matches, the query dataset will be empty.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    Okay. Can you help me with the first part then?

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Did you try the UNMATCHED query wizard?

  5. #5
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    Yea but you can't do it to multiple fields in one query. It only lets you match one

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    220 , even 140 fields in a table is extremely rare.
    Tell us about the data, tell us about the file.
    Why are you using 64 bit Office?

    You can do, at least in theory, what you want by using 2 records sets.

    Read Rs1 and rs2, compare field by field,
    if rs1.fieldX <>rs2.fieldX then report the unmatch

    Can you post the table structures? Or say 50 records from each table, and a description of how specifically the fields should match/not match?

    Note: untested

    Something like this might work

    Code:
    SELECT tbl220.Id
    , tbl220.Field1
    , tbl220.Field2,
    ....
    tbl220.Field220
    FROM 
    tbl220 LEFT JOIN tbl140 
     ON tbl220.Key = tbl140.key  And
        tbl220.field1 = tbl140.field1  and
        tbl220.field2 = tbl140.field2
        ......
    WHERE (((tbl220.somekeyfield) Is Null));
    You could also try Untested
    do a matching query (Inner Join query) and then do a query to find things in in tbl220 and not in the InnerJoin query.

    Just some thoughts to consider. It would be better if readers knew about WHY you need this, and more about the tables involved.

  7. #7
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    I can't post this database because it has private patient informarion. But I don't need all of the fields from each table to match each other. There is only going to be about 20 that I need to match up and find if there is unmatched data for. The WHERE clause in your code where it says "(((tbl220.somekeyfield)" is that PK from the beginning of the code "SELECT tbl220.Id" ?

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    I was just suggesting some things as I dreamt them up.
    Test a few things with some sample data. Make sure it works then add more until you get what you need.

  9. #9
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    SELECT PVE.*
    FROM PVE, TEST_EEAF
    WHERE PVE.HICN LIKE "%" & TEST_EEAF.HICN & "%";

    Won't this code compare the field name HICN from both of the tables and if there is an unmatched record display that record from the PVE table?

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    No, you don't have any Join defined.
    You get a cartesian product and your Where clause doesn't make sense.

    This would be basic to find matches:
    Code:
    SELECT PVE.*
    FROM PVE, TEST_EEAF
    WHERE PVE.HICN = TEST_EEAF.HICN;
    OR

    Code:
    SELECT PVE.*
    FROM PVE INNER JOIN TEST_EEAF
    ON PVE.HICN = TEST_EEAF.HICN;

  11. #11
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    Okay, But I am trying to a solution that lets me check multiple different fields like about 20. I don't want to have to write that over and over again to compare each field

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

Similar Threads

  1. Replies: 3
    Last Post: 06-26-2014, 08:35 AM
  2. Unmatch Query
    By NOEL71 in forum Queries
    Replies: 1
    Last Post: 06-18-2014, 06:55 AM
  3. Replies: 2
    Last Post: 08-10-2013, 06:06 PM
  4. Match/Unmatch Query need
    By kwooten in forum Queries
    Replies: 5
    Last Post: 11-08-2012, 01:26 PM
  5. Replies: 1
    Last Post: 04-30-2012, 08: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