Results 1 to 5 of 5
  1. #1
    DrCadd is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2013
    Posts
    3

    Comparing two tablse - searching for orphans


    My database has three tables. Two of them are named X3FROM2 and X3TO2. They represent tie points between drawings.
    For every connect in the TO table there should be a corresponding incoming connection in the FROM table. So, lets say a record in the FROM table reads:
    Point From/To From/To Dwg On Dwg <- these are the field names
    A FROM LDAR-020 LDAR-019

    there should be a corresponding record in the TO table that reads:
    Point From/To From/To Dwg On Dwg <- these are the field names
    A TO LDAR-019 LDAR-020

    I need a query to identify entries in either table that do not have a corresponding record. I'm clueless. Attached is my table.
    Thank you.
    Attached Files Attached Files

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    This query will give you all entries in table FROM with no corrresponding entry in the TO table

    Code:
    SELECT X3FROM2.Point, X3FROM2.[From/To Dwg], X3TO2.[From/To Dwg], X3FROM2.[On Dwg], X3TO2.[On Dwg]
    FROM X3FROM2 LEFT JOIN X3TO2 ON X3FROM2.[From/To Dwg] = X3TO2.[From/To Dwg]
    WHERE (((X3TO2.[From/To Dwg]) Is Null));
    This query will give you the opposite
    Code:
    SELECT X3FROM2.Point, X3FROM2.[From/To Dwg], X3TO2.[From/To Dwg], X3FROM2.[On Dwg], X3TO2.[On Dwg]
    FROM X3FROM2 RIGHT JOIN X3TO2 ON X3FROM2.[From/To Dwg] = X3TO2.[From/To Dwg]
    WHERE (((X3FROM2.[From/To Dwg]) Is Null));

  3. #3
    DrCadd is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2013
    Posts
    3
    Thank you very much!

  4. #4
    DrCadd is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2013
    Posts
    3

    False Positives

    Your query seemed to work correctly on the first table I tried it on. However, when I tried it on a new database today it gave me a lot of false positives. Attached is the new database.Cont Check.zip

  5. #5
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    I think that you have the Is null in the Orphans in the TO table in the wrong field. try this.

    Code:
    SELECT X3FROM2.Point, X3FROM2.[From/To Dwg], X3TO2.[From/To Dwg], X3FROM2.[On Dwg], X3TO2.[On Dwg]
    FROM X3FROM2 RIGHT JOIN X3TO2 ON X3FROM2.[From/To Dwg] = X3TO2.[From/To Dwg]
    WHERE (((X3FROM2.[From/To Dwg]) Is Null));

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

Similar Threads

  1. Temp table to prevent orphans
    By Tvanduzee in forum Database Design
    Replies: 1
    Last Post: 08-14-2012, 12:10 PM
  2. Searching between two dates
    By desk4tbc in forum Programming
    Replies: 3
    Last Post: 10-13-2011, 07:26 PM
  3. Searching a Subform
    By desireemm1 in forum Forms
    Replies: 5
    Last Post: 10-03-2011, 06:01 PM
  4. Searching asking for Parameters
    By Zerdan in forum Forms
    Replies: 1
    Last Post: 05-31-2011, 05:20 PM
  5. Advanced Searching
    By mbolster in forum Forms
    Replies: 3
    Last Post: 07-06-2010, 10:10 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