Results 1 to 2 of 2
  1. #1
    JonathanOz is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Location
    Santa Monica, CA USA
    Posts
    6

    Identify records in one table that share values with at least one record in another table.

    I have two tables: One contains counts data for state highways. The other contains information on a segmentation scheme for each of the highways. Both tables contain a variable entitled Route Number. Every possible Route Number is in Table One. Only record numbers for routes where segments have been defined are in Table Two. The two files are each sorted by Route Number, and values of Route Number repeat themselves in each file.
    I want to create a Boolean Variable (True/False) in a query that will indicate for each record in Table One whether its value for Route Number exists in any record in Table Two
    An Example may prove helpful
    Table One Table Two
    Route Number Route Number
    2 5
    2 5
    5 10
    5 10
    5 105
    10 710
    10 710
    10
    10
    91
    105
    710



    Result Query
    Value of Route Number from
    Records inTable One
    Boolean Variable Reason for Value of Boolean
    2 False No Record in File Two has Route Number=2
    2 False No Record in File Two has Route Number=2
    5 True At least one record in File Two has Route Number=5
    5 Tue At least one record in File Two has Route Number=5
    5 True At least one record in File Two has Route Number=5
    10 True At least one record in File Two has Route Number=10
    10 True At least one record in File Two has Route Number=10
    10 True At least one record in File Two has Route Number=10
    10 True At least one record in File Two has Route Number=10
    91 False No Record in File Two has Route Number=91
    105 True At least one record in File Two has Route Number=105
    710 True At least one record in File Two has Route Number=710
    How can I create the result query?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Options:

    1. involves at least 2 queries
    SELECT [Route Number], Count(*) AS RecordCount FROM table2 GROUP BY [Route Number];

    Now build another query that joins the above query to table1 - join type "Retrieve all records from table1 and only those from query that match"

    2. involves domain aggregate function in 1 query
    SELECT *, IIf(DCount("[Route Number]", "table2", "[Route Number]=" & [Route Number])=0, False, True) AS RecordCheck FROM table1;

    Or if you want to show the count:

    SELECT *, DCount("[Route Number]", "table2", "[Route Number]=" & [Route Number]) AS RecordCount FROM table1;
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 02-03-2013, 01:11 PM
  2. Replies: 2
    Last Post: 11-12-2012, 03:52 AM
  3. Replies: 8
    Last Post: 02-26-2012, 09:48 PM
  4. MS Access sum values of one field in all records of one table
    By logamuthu in forum Import/Export Data
    Replies: 2
    Last Post: 11-22-2011, 12:39 PM
  5. Replies: 0
    Last Post: 10-23-2008, 12:08 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