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 8682705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:50:46+00:00 2026-06-12T21:50:46+00:00

Sorry for the mega title… I was trying to be descriptive enough. I’ve got

  • 0

Sorry for the mega title… I was trying to be descriptive enough. I’ve got a table that contains event attendance data that has some erroneous data in it. The table definition is kind of like this:

id (row id)
date
company_name
attendees

It ended up with some cases where for a given date, there are two entries matching a company_name and date but one has attendees=0 and the other has attendees>0. In those cases, I want to discard the ones where attendees=0.

I know you can’t join on the same table while deleting, so please consider this query to be pseudocode that shows what I want to accomplish.

DELETE FROM attendance a WHERE a.attendees=0 AND a.date IN (SELECT b.date FROM attendance b WHERE b.attendees > 0 AND b.company_name = a.company_name);

I also tried to populate a temporary table with the ids of the rows I want to delete, but that query hangs because of the IN (SELECT …) clause. My table has thousands of rows so that just maxes out the CPU and then times out.

  • 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-12T21:50:47+00:00Added an answer on June 12, 2026 at 9:50 pm

    This ugly thing should work (using alias permit to avoid the You can't specify target table for update in FROM clause error)

    DELETE FROM attendance
    WHERE (attendees, date, company_name)
    IN (SELECT c.a, c.d, c.c 
        FROM
         (SELECT MIN(attendees) a, date d, company_name c
          FROM attendance
          GROUP BY date, company_name
          HAVING COUNT(*) > 1) as c);
    

    SqlFiddle

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

Sidebar

Related Questions

Sorry the title is not very descriptive but it is a tricky problem to
Sorry if the title is not clear enough, I have <a> elements with the
Sorry for the title but I believe it is what I am trying to
Sorry the title isn't more help. I have a database of media-file URLs that
Sorry if the title is poorly descriptive, but I can't do better right now
Sorry about the cranky title, here's the example: <table> <tr> <th class=hey-1-aa></th> </tr> <tr>
First up, sorry for the mega-posting of code but... I have the following DB
Sorry for the bad title - I simply do not know what to call
Sorry if it looks so simple. Am trying to find when W3wp.exe will show
Sorry if the title is a little... vague. Anyway, I'm making a platformer using

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.