Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8814283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:04:43+00:00 2026-06-14T04:04:43+00:00

I am working with a database table that stores, among other things, an AssociateID

  • 0

I am working with a database table that stores, among other things, an AssociateID field and a DocumentName field. The table is used to keep records of which associates are missing which documents.

I am trying to write a stored procedure that will remove a row for ‘Restrictive Covenant Letters’ if an entry for ‘Termination Statement’ cannot be found for the same associate. Below is the body of what I have so far:

DELETE from tbl_HR_Auditing_Reports
WHERE DocumentName = 'Restrictive Covenant Letters'
AND NOT EXISTS
    (
        SELECT TS.AssociateID
        FROM
            (SELECT AssociateID FROM tbl_HR_Auditing_Reports WHERE DocumentName = 'Termination Statement (*)') TS,
            (SELECT AssociateID FROM tbl_HR_Auditing_Reports WHERE DocumentName = 'Restrictive Covenant Letters') RCL
        WHERE  TS.AssociateID = RCL.AssociateID
    )

I think I am close, but sql isn’t really my forte. If anyone could possibly help, I would really appreciate it!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:04:44+00:00Added an answer on June 14, 2026 at 4:04 am

    According to the MySQL manual:

    Currently, you cannot delete from a table and select from the same table in a subquery.

    To get around this you can use a temporary table, inserting the relevant rows into the temporary table, then referencing it in the delete statement.

    CREATE TEMPORARY TABLE tmp (AssociateID INT);
    INSERT INTO tmp (AssociateID)
    SELECT  AssociateID
    FROM    tbl_HR_Auditing_Reports
    WHERE   DocumentName = 'Termination Statement (*)';
    
    DELETE 
    FROM    tbl_HR_Auditing_Reports 
    WHERE   DocumentName = 'Restrictive Covenant Letters'
    AND     NOT EXISTS
            (   SELECT  1
                FROM    tmp
                WHERE   tmp.AssociateID = tbl_HR_Auditing_Reports.AssociateID
            )
    

    Example on SQL Fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a legacy database table that has a phone no. field but
I'm working on an application that stores user inputs into the database table via
Here's the scenario: I'm working with a database table that stores an XML string
I'm working with a table and there is field in my table which stores
I have a database which has a table that stores medical conditions and another
Working on a website that has Employee and Branch entities, using a database table
The database I'm working against has table names such as table_name. That's fine, but
I'm working with an asp.net application that stores most data in a database and
I have one problem... There is a table in my MySQL database that stores
I have an asp.net website that stores events inside a database table. Then I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.