Results 1 to 5 of 5
  1. #1
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150

    Compare codes between two tables, return non-similar codes + fields

    Hi,

    Not sure where to begin, queries are my weakness!

    I have two tables, one is "Master", other is "Actual". Both have a field "Code". Only ACTUAL has a field "POSITION"

    I need to return a list of all items inside ACTUAL where the code in ACTUAL does not equal the code for that same item in MASTER, as well as return it's associated fields ("POSITION") in ACTUAL.

    I was able to compare them using the query wizard which resulted in a left join, but that compared them completely, not sure how to add criteria to filter them for results where ActualCode <> MasterCode.

    Here is schema info:

    1.) MASTER may contain thousands of ItemIDs (speed important) - But the ItemID in master will ALWAYS be unique

    2.) ACTUAL may only contain a dozen or two ItemIDs - But may have duplicate IDs with varying codes

    3.) There is a possibility that an ItemID in ACTUAL may not exist in MASTER - and I would love a way to identify this occurrence in the resultant query.


    Attached is test DB + images of expected results.

    Thanks for any help!
    Attached Thumbnails Attached Thumbnails results.png  
    Attached Files Attached Files

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Your return results don't match the data shown

    Perhaps this will do what you want:
    Code:
    SELECT ACTUAL.ID, ACTUAL.ItemID, ACTUAL.Code, MASTER.Code, ACTUAL.ItemPosition 
    FROM ACTUAL LEFT JOIN MASTER ON ACTUAL.ID = MASTER.ID
    WHERE MASTER.Code<>Actual.Code Or MASTER.Code Is Null;
    Result:
    Click image for larger version. 

Name:	Capture.PNG 
Views:	10 
Size:	7.5 KB 
ID:	40271

    Calling a field 'code' isn't a good idea as it played havoc with the code tags here!
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150
    Isladogs,

    Thanks for replying,

    My results match the data i provided. Albeit, they are manually generated.
    I'm not sure what your results are providing. They do not meet requirements.
    Every itemID has a master code, so why yours does not display this information is puzzling

  4. #4
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150
    Update:

    Solved using a LEFT JOIN.

    This displays all items in actual where codes do not match master.
    And returns any items in Actual that do not exists in master.

    Thanks

    CompareCodes_Solved.accdb.zip

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    I used your data to generate those query results linking the tables using the ID field following what I understood you wanted.

    Your results include ID=7 even though the code values are identical in both tables.
    Because the values are identical, my query excludes that value.
    I realise the ItemID is different in each table for ID=7. Perhaps that's what you wanted to link the tables on instead?

    ID values 9 and 10 do not exist in the master table hence those records are blank.
    You asked for that info in point 3 of your first post.

    The issue with the Code field was when I uploaded the query sql including e.g. [Actual].[Code] using the site code tags as it confused the forum software.

    As my attempt doesn't meet your requirements, I'll leave you to adapt it as you want.

    EDIT
    Posts crossed. Glad you've solved it for yourself.
    As I suspected you wanted to link on ItemID rather than ID. Otherwise same idea as my attempt.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. DB return codes?
    By GraeagleBill in forum Access
    Replies: 15
    Last Post: 07-03-2018, 02:56 PM
  2. Zip codes
    By joecamel9166 in forum Access
    Replies: 4
    Last Post: 04-01-2016, 02:12 PM
  3. return data for similar fields
    By kwooten in forum Queries
    Replies: 5
    Last Post: 08-06-2013, 02:18 PM
  4. Zip Codes
    By Laurie B. in forum Access
    Replies: 6
    Last Post: 02-25-2011, 02:38 PM
  5. Replies: 1
    Last Post: 09-01-2006, 03:49 PM

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