• Delete query to remove orphan records (Access 97)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Delete query to remove orphan records (Access 97)

    Author
    Topic
    #373957

    I have an Access 97 database which was set up without relationships between tables. Unfortunately, I now have orphan records in one table which don’t have a corresponding match in a second table. I need an SQL statement that will run a Delete Query to remove these records.

    The common field between the 2 tables is ‘ExtensionID’. TableA contains records with ExtensionID’s that have no corresponding match in TableB.

    Help, please!!!

    Viewing 1 reply thread
    Author
    Replies
    • #602970

      Try

      DELETE tblA.*, tblA.PrimaryKey
      FROM tblA
      WHERE (((tblA.PrimaryKey) Not In (select ForeignKey FROM tblB)));

      Where PrimaryKey and ForeignKey are the fields that you would join on.

    • #603106

      Here’s an alternative query:

      DELETE DISTINCTROW TableA.*
      FROM TableA LEFT JOIN TableB ON TableA.ExtensionID = TableB.ExtensionID
      WHERE (((TableB.ExtensionID) Is Null));

    Viewing 1 reply thread
    Reply To: Delete query to remove orphan records (Access 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: