Results 1 to 9 of 9
  1. #1
    sam81 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    7

    Query to compare two columns in two separate tables for identical values

    I'm just not sure of the language to use to do this in the Criteria section of Query Design.

    Basically, I'm looking to see if the same customer IDs are present in two separate tables. This would indicate double payments. Both tables have a customer ID column.

    For example, if the customer ID 12345 is present in both tables, then a double payment was made.

    I tried this in Excel (using =ISNA/Match formula) but the number of rows is close to 100,000 and it locks up. I'm new to Access and hoping there's something that could do this.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Could try Find Unmatched query. There is a wizard for that.
    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
    sam81 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    7
    Quote Originally Posted by June7 View Post
    Could try Find Unmatched query. There is a wizard for that.
    Well, the description in the Unmatched Query wizard states that it will find rows in one table that have no related records in another table. I need it to find rows in one table that do have related (identical) records in another table.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Sorry, misread post.

    Then that is just a SELECT query with INNER JOIN.
    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.

  5. #5
    sam81 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    7
    Here's the syntax I'm attempting, but it keeps causing an error message. I know I'm probably overlooking something minor, still new to this.

    The two tables are "19m" and "34m". Both tables contain a column called "Claim ID".

    SELECT;
    FROM 19m INNER JOIN 34m ON 19m.Claim ID = 34m.Claim ID

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Why is the ; following SELECT? Should be at end of statement. Did you manually type in SQL View? Use the builder then look at statement in SQL View.
    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.

  7. #7
    sam81 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    7
    Quote Originally Posted by June7 View Post
    Why is the ; following SELECT? Should be at end of statement. Did you manually type in SQL View? Use the builder then look at statement in SQL View.
    I manually typed this in SQL View based off of an example I found during a search online. I placed the ";" after the entire statement, here's what it looks like now:

    SELECT
    FROM 19m INNER JOIN 34m ON 19m.Claim ID = 34m.Claim ID;

    It's still not working though. I am not sure how to use the builder using the INNER JOIN function. Is the builder essentially the query Design View? Would I place the INNER JOIN in the Criteria section?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,896
    Yes, query Design View. Create the JOIN clause by establishing a link line between the tables. Click key field in one table, hold and drag to key field in other table. If you set up relationship in Relationships builder the query would automatically generate the link.

    However, the reason for failure is probably the spaces in field names. Enclose in [], like: [Claim ID]. If you used the Designer, it should supply the [] for you.

    Advise not to use spaces and special characters/punctuation (underscore is exception) in naming convention. Also, do not use reserved words, like Name and Date, as names.

    This is basic Access query design functionality. Search Access Help or web for more info.
    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.

  9. #9
    sam81 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2015
    Posts
    7
    Quote Originally Posted by June7 View Post
    Yes, query Design View. Create the JOIN clause by establishing a link line between the tables. Click key field in one table, hold and drag to key field in other table. If you set up relationship in Relationships builder the query would automatically generate the link.

    However, the reason for failure is probably the spaces in field names. Enclose in [], like: [Claim ID]. If you used the Designer, it should supply the [] for you.

    Advise not to use spaces and special characters/punctuation (underscore is exception) in naming convention. Also, do not use reserved words, like Name and Date, as names.

    This is basic Access query design functionality. Search Access Help or web for more info.
    Wow that was so easy with the builder. It found the identical results I was looking for. THANK YOU! I just dragged and dropped the Claim ID from one table to the other.

    I can now see the SQL view and see how far I was off with my code.

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

Similar Threads

  1. Replies: 10
    Last Post: 11-25-2014, 06:35 PM
  2. Replies: 5
    Last Post: 08-22-2014, 05:01 AM
  3. Replies: 2
    Last Post: 07-03-2014, 08:28 PM
  4. Replies: 10
    Last Post: 05-22-2013, 02:56 PM
  5. Replies: 1
    Last Post: 03-12-2013, 01:20 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