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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:44:35+00:00 2026-05-23T13:44:35+00:00

I have a fairly simple table with approx a million rows. id | my_col

  • 0

I have a fairly simple table with approx a million rows.

id  |  my_col  |  other1  |  other 2 | ...

There are about 15k distinct my_col values in this table and I have an index on my_col. I have a set of 7k my_col values that I need to remove from this table.

What is the more efficient thing to do in SQL (I’m currently working with MySQL, but may port to MS SQL in future).

Is it a) In my java app code, itterate through all the my_col values and call sql delete on each one.

for (String my_colValue : listMyCol) {
   [delete from my_table where my_col = my_colValue]
}

or b) Build up a single SQL [large] statement containing all these values using the “where in” clause ?

delete from my_table where my_col in ('aaa', 'aab', 'aac', ...)

I’d guess it is b), but I’m not sure if specifying about 7k values in this “where in” clause becomes inefficient.

For what its worth, my app server and database server are both hosted in Amazon, but on separate tiers.

  • 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-23T13:44:36+00:00Added an answer on May 23, 2026 at 1:44 pm

    c) Recreate your table.

    You are going to delete half of you rows, so think about it.
    While a) and b) will take maybe forever, recreate your table will be tricker but immediate.

    And you need to load your 7k values in a temporary tables, then it is easy :

    CREATE TABLE newMyTable
    AS
    SELECT myTable.*
    FROM myTable
        INNER JOIN myValues
            ON myTable.my_col = myValues.my_col
    

    Or if you can’t create table, maybe this will be fast enough :

    DELETE FROM myTable t
    WHERE EXISTS
    (
        SELECT *
        FROM myValues v
        WHERE t.my_col = v.my_col
    )
    

    But the only things you need to keep in mind : you have to create a table with your 7k values.

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

Sidebar

Related Questions

I have a fairly simple sync problem. I have a table with about 10
I have a fairly simple table requestparams ( requestid varchar(64) NOT NULL, requestString text,
I have a fairly simple table called widgets. Each row holds an id, a
I have a fairly simple cell in a table with an inline style: <td
I have a fairly simple requirement -I have a table with the following (relevant)
I have a fairly simple table (forgive errors / stupidity, I'm still learning. Written
I have a fairly simple dynamic html structure of a table that contains links
I have a fairly simple question about natural/surrogate key usage in a well-defined context
I have a fairly simple ASP.NET 2.0 menu control using a sitemap file and
I have a fairly simple const struct in some C code that simply holds

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.