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

  • SEARCH
  • Home
  • 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 7172433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:36:52+00:00 2026-05-28T15:36:52+00:00

I now have a table that has 604 000 row. I would like to

  • 0

I now have a table that has 604 000 row. I would like to drop 4000 random rows so my table will only contains 600 000 entries.

Would there be a quick way to do so ?

Thanks a lot.

  • 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-05-28T15:36:53+00:00Added an answer on May 28, 2026 at 3:36 pm

    In theory, this will be random and fast. In practise, it will be only fast:

    DELETE FROM tableX
    LIMIT 4000
    

    This will be random but terribly slow, with 600K rows:

    DELETE FROM tableX
    ORDER BY RAND() 
    LIMIT 4000
    

    This won’t be truly random (as there are usually gaps in the ids) and it may not even delete exactly 4000 rows (but a few less when there are many gaps) but it’s probably faster than the previous.

    An extra wrapping in a subquery is needed because the syntax for Delete from multiple tables does not allow LIMIT:

    DELETE td
    FROM
          tableX AS td
      JOIN 
          ( SELECT t.id
            FROM
                 tableX AS t 
              CROSS JOIN
                  ( SELECT MAX(id) AS maxid 
                    FROM tableX
                  ) AS m
              JOIN
                  ( SELECT RAND() AS rndm
                    FROM tableX AS tr
                    LIMIT 5000
                  ) AS r
                ON 
                   t.id = CEIL( rndm * maxid )
            LIMIT 4000
          ) AS x
          ON 
             x.id = td.id 
    

    Explain output (of the subquery, from a 400K rows table):

    id           table        possible_keys  key_len     rows 
     select_type         type             key     ref         Extra
    1 PRIMARY <derived2> system                             1
    1 PRIMARY <derived3> ALL                             5000
    1 PRIMARY t          eq_ref PRIMARY PRIMARY 4 func      1 Using where;Using index
    3 DERIVED tr         index          PRIMARY 4      398681 Using index
    2 DERIVED                                            Select tables optimized away
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large table (~1M rows now, soon ~10M) that has two ranked
I have a table that has about 400,000+ rows. I am writing some pattern
Right now I have a table called Campaigns that has many Hits, if I
I have a table that has 7000 rows, I added a new column to
I have a table that has some rows in it. Here is an example
I have a table that has data like below(sorted by date) COL_A | COL_B
I have a database table on a development server that is now fully populated
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
Good afternoon I have a table that has customer id, name, computer, laptop, blah,
I have SQL table that has a varchar(8) column that occasionally has binary data

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.