Results 1 to 10 of 10
  1. #1
    dakpluto is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2012
    Posts
    18

    Match and then unmatched

    I need to do a query that first matches two common fields between two tables, and then display a second field between the two that does not match.



    Example:

    Number Name
    1 Johnson
    2 Kerry
    3 Hancock
    4 Jefferson
    5 Harris
    6 O'Neal
    7 Larkin
    8 Millsap
    9 Harvey
    10 Harrison
    Number Name
    1 Johnson
    2 Howard
    3 Hancock
    4 Jefferson
    5 Harrison
    6 O'Neal
    7 Larkin
    8 James
    9 Harvey
    10 Harold


    I would need the query to match the records by the number column first, and then display the records that do not match the name column. So in this example, it should return numbers 2, 5, 8, 10. I cannot just simply run an unmatched on the two name columns, because as you can tell, 10 would not kick because the last name is also in 5 in the other table.

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Sure, you can do an Unmatched query between the two. You just need to include BOTH fields in your Join.
    Then it will only return records where BOTH fields do not match (which I think is what you are looking for).

  3. #3
    DepricatedZero's Avatar
    DepricatedZero is offline Cthulhu Fhtagn!
    Windows 8 Access 2007
    Join Date
    Apr 2013
    Location
    Cincinnati
    Posts
    65
    Perhaps this is a shortcoming on my part, but this seems like two separate queries to me.

  4. #4
    dakpluto is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    18
    No, I need to match the first field. Here is the issue, somebody screwed up a bunch names in one database. So I have to match the account number from a master list to the screwed up database. Then show those matched records where the last names do not match so i can repair them. So I have to MATCH, then do an unmatched. Like my example above, it first matches 1 to 1, then looks at the last name. If they match, ignore and move on. If the last names do not match, output it.

  5. #5
    dakpluto is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    18
    Quote Originally Posted by DepricatedZero View Post
    Perhaps this is a shortcoming on my part, but this seems like two separate queries to me.
    Not opposed if it requires more, but I need to make sure the records retain that matching when it check the unmatched. Otherwise, like in my example above, Account 10 in the first table would not output because the last name Harrison is present in the messed up table and wouldn't count as unmatched.

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I don't think you are understanding what I am telling you. The steps that I mentioned will return records 2,5,8, and 10. That is what you want, right?

    The SQL code of that unmatched query might look something like:
    Code:
    SELECT Table1.*
    FROM Table1 
    LEFT JOIN Table2 
    ON Table1.Name = Table2.Name 
    AND Table1.Number = Table2.Number
    WHERE Table2.Number Is Null;

  7. #7
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    This link may be helpful http://allenbrowne.com/subquery-01.html

  8. #8
    dakpluto is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    18
    Quote Originally Posted by JoeM View Post
    I don't think you are understanding what I am telling you. The steps that I mentioned will return records 2,5,8, and 10. That is what you want, right?

    The SQL code of that unmatched query might look something like:
    Code:
    SELECT Table1.*
    FROM Table1 
    LEFT JOIN Table2 
    ON Table1.Name = Table2.Name 
    AND Table1.Number = Table2.Number
    WHERE Table2.Number Is Null;
    ok, access kinda screwed it up with their default joins, but this worked well, thank you.

  9. #9
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    If you were using the Access Unmatched Query Wizard, they will only do one join for you, so you usually need to go in and manually add the second join.

  10. #10
    dakpluto is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    18
    I added the second join manually in design but the SQL code wasn't working with it.

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

Similar Threads

  1. Query and unmatched records
    By jlgray0127 in forum Forms
    Replies: 1
    Last Post: 03-19-2012, 05:56 PM
  2. Replies: 16
    Last Post: 03-13-2012, 03:47 PM
  3. Help! Unmatched Records Query
    By Hberg in forum Access
    Replies: 1
    Last Post: 03-09-2012, 03:41 PM
  4. Replies: 1
    Last Post: 12-08-2011, 01:52 PM
  5. Unmatched query on 1 table
    By tmcrouse in forum Access
    Replies: 7
    Last Post: 06-01-2011, 08:38 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