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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:10:58+00:00 2026-06-17T02:10:58+00:00

I have a rather complex DELETE query that I need to break down into

  • 0

I have a rather complex DELETE query that I need to break down into batches, but I can’t do that until I can determine how many rows would be deleted before performing the query. Here is the query that I want to get a count on:

DELETE parts, binaries FROM parts LEFT JOIN binaries ON binaries.ID = parts.binaryID LEFT JOIN releasenfo rn ON rn.binaryID = binaries.ID WHERE binaries.procstat IN (4, 6) AND (rn.binaryid IS NULL OR (rn.binaryid IS NOT NULL AND rn.nfo IS NOT NULL))) OR binaries.dateadded < '2013-01-04 22:01:17' - INTERVAL 36 HOUR;

Here is what I thought might work, but it’s not valid:

Select COUNT(*) FROM (DELETE parts, binaries FROM parts LEFT JOIN binaries ON binaries.ID = parts.binaryID LEFT JOIN releasenfo rn ON rn.binaryID = binaries.ID WHERE binaries.procstat IN (4, 6) AND (rn.binaryid IS NULL OR (rn.binaryid IS NOT NULL AND rn.nfo IS NOT NULL))) OR binaries.dateadded < '2013-01-04 22:01:17' - INTERVAL 36 HOUR) AS countme;

Can someone please point me in the right direction?

To put this into context, I want to use it with the following php pseudo code:

$limit = 10000; // Do in batches to give user status            
$totalRows = $db->query("Count query goes here");

while($rowsLeft > 0)
{
    echo "$rowsLeft remaining to be deleted\n";
    $db->query("DELETE ...... LIMIT ".$limit);
    $rowsLeft -= $limit;
}   
  • 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-17T02:10:59+00:00Added an answer on June 17, 2026 at 2:10 am

    You can simply try this:

    SELECT * FROM parts p 
    LEFT JOIN binaries b ON b.ID = p.binaryID AND b.procstat IN (4, 6) 
    LEFT JOIN releasenfo rn ON rn.binaryID = b.ID 
    WHERE rn.binaryid IS NULL OR (rn.binaryid IS NOT NULL AND rn.nfo IS NOT NULL) OR 
            b.dateadded < '2013-01-04 22:01:17' - INTERVAL 36 HOUR;
    
    DELETE p, b FROM parts p 
    LEFT JOIN binaries b ON b.ID = p.binaryID AND b.procstat IN (4, 6) 
    LEFT JOIN releasenfo rn ON rn.binaryID = b.ID 
    WHERE rn.binaryid IS NULL OR (rn.binaryid IS NOT NULL AND rn.nfo IS NOT NULL) OR 
            b.dateadded < '2013-01-04 22:01:17' - INTERVAL 36 HOUR;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number rather large, complex xml documents that I need to loop
I have this rather complex query that grabs data from three tables, and now
Have a (rather complex) app that works fine on iOS 4 but fails on
I have a rather complex situation that I need to get working, for some
I have a rather complex query that pretty much mimics a test query I
I have a window that contains several rather complex views. Right now, I'm using
I have a PHP class that stores a complex multidimensional array, and rather than
I have some rather odd behavior in my D program that I've narrowed down
I have a legacy class that is rather complex to maintain: class OldClass {
I need to make a rather complex query, and I need help bad. Below

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.