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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:31:35+00:00 2026-05-15T05:31:35+00:00

I’m getting a very strange behavior in MySQL, which looks like some kind of

  • 0

I’m getting a very strange behavior in MySQL, which looks like some kind of weird bug. I know it’s common to blame the tried and tested tool for one’s mistakes, but I’ve been going around this for a while.

I have 2 tables, I, with 2797 records, and C, with 1429. C references I.
I want to delete all records in I that are not used by C, so i’m doing:

select * from i where id not in (select id_i from c);

That returns 0 records, which, given the record counts in each table, is physically impossible. I’m also pretty sure that the query is right, since it’s the same type of query i’ve been using for the last 2 hours to clean up other tables with orphaned records.

To make things even weirder…

select * from i where id in (select id_i from c);

DOES work, and brings me the 1297 records that I do NOT want to delete.
So, IN works, but NOT IN doesn’t.

Even worse:

select * from i where id not in (
  select i.id from i inner join c ON i.id = c.id_i
);

That DOES work, although it should be equivalent to the first query (i’m just trying mad stuff at this point).
Alas, I can’t use this query to delete, because I’m using the same table i’m deleting from in the subquery.

I’m assuming something in my database is corrupt at this point.

In case it matters, these are all MyISAM tables without any foreign keys, whatsoever, and I’ve run the same queries in my dev machine and in the production server with the same result, so whatever corruption there might be survived a mysqldump / source cycle, which sounds awfully strange.

Any ideas on what could be going wrong, or, even more importantly, how I can fix/work around this?

Thanks!
Daniel

  • 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-15T05:31:35+00:00Added an answer on May 15, 2026 at 5:31 am

    I would guess that you have a row containing a NULL value. IN and NOT IN behave in a way that you might not expect when there are NULL values. From the manual:

    To comply with the SQL standard, IN returns NULL not only if the expression on the left hand side is NULL, but also if no match is found in the list and one of the expressions in the list is NULL.

    The value of NOT NULL is still NULL, not true as you hoped.

    Here’s a demonstration of the behaviour on a simplified example:

    CREATE TABLE c (id_i INT NULL);
    INSERT INTO c (id_i) VALUES
    (1),
    (2),
    (NULL);
    
    CREATE TABLE i (id INT NOT NULL);
    INSERT INTO i (id) VALUES
    (1),
    (2),
    (3);
    
    SELECT * FROM i WHERE id NOT IN (SELECT id_i FROM c); -- returns nothing
    SELECT * FROM i WHERE id IN (SELECT id_i FROM c);     -- returns 1,2
    SELECT * FROM i WHERE id NOT IN (                     -- returns 3
      SELECT i.id FROM i INNER JOIN c ON i.id = c.id_i
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to run a str_replace or preg_replace which looks for certain words
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have an autohotkey script which looks up a word in a bilingual dictionary
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

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.