Results 1 to 3 of 3
  1. #1
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153

    How to compare 2 tables and pull information based on 2 criteria

    I am an intermediate access user, with very little to ZERO SQL knowledge. Here is my issue.

    I have 2 tables that I want to compare and only pull specific records for voters that fit 2 criteria:
    1. Pull only records with a matching “VID” field
    2. Then with the VID’s that DO match, look at the “Address” field and only show records where the Address doesn’t match

    I have the 2 tables attached, but wanted to paint a picture here….


    Table 1 (In reality this table has over a million records):
    VID (Primary Key) First Name Last Name Address City
    111 John Smith 1234 main st Seattle
    222 Eric Jenner 7890 low st Renton
    333 Tina Fey 555 High st # 201 Tukwila
    444 Leland Buck 888 S place Seattle
    555 Vicki Moore 666 Satan’s lair Tacoma


    Table 2 (this table has about 200-1000 records):
    VID (Primary Key) Address City
    111 1234 main st Seattle
    222 999 Main St Seattle
    333 4444 Low St Tukwila


    I would like to create a query (below) that compares these 2 tables and then would show the following records:
    Query:
    VID (Primary Key) Address City
    222 999 Main St Seattle
    333 4444 Low St Tukwila


    This query only pulls 2 records because only these 2 records match the criteria of 1- Same VID, then 2- The address fields DO NOT match (i don't care about city)

    I cannot figure how to do this in 1 step, currently I have to run 2 query’s to get this, 1 to look at the matching VID’s and the other to look for address’s that are different.
    Can someone help create a query for me that will pull the information I need?

    Test_DB.zip

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Create a query in design view - it will do the SQL for you so you don't have to worry about that. Bring in table1 and table2 and join on VID. Select Address field from table1 and in the criteria field say "<>table2.address"

  3. #3
    KingOf206 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Seattle
    Posts
    153
    Wow, that was way easier than i thought! Thank you so much aytee111 !! Huge help!

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

Similar Threads

  1. Replies: 1
    Last Post: 06-14-2017, 02:10 PM
  2. Replies: 8
    Last Post: 10-23-2013, 04:37 PM
  3. Replies: 2
    Last Post: 08-10-2013, 06:06 PM
  4. Replies: 3
    Last Post: 04-24-2013, 08:29 AM
  5. Replies: 6
    Last Post: 02-25-2013, 07:27 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