I get a very strange behavior in MySQL that looks like some kind of strange error. I know that it’s just blaming a tried and tested tool for one mistake, but I went around this for a while.
I have 2 tables, I, with 2797 entries and C, from 1429. C links I.
I want to delete all entries in I that are not used by C, so I do:
select * from i where id not in (select id_i from c);
This returns 0 records, which, given the number of records in each table, is physically impossible. I am also sure that the query is right, because the same type of query that I used in the last 2 hours to clear other tables with lost records.
To make things even weirder ...
select * from i where id in (select id_i from c);
It works, and brings me 1297 entries, which I DO NOT want to delete.
So, IN works, but NOT IN does not.
Even worse:
select * from i where id not in (
select i.id from i inner join c ON i.id = c.id_i
);
This works, although it should be equivalent to the first request (I'm just trying to figure it out at the moment).
Alas, I cannot use this query to delete, because I use the same table in which I am removed from the subquery.
I assume that something in my database is corrupted at the moment.
In case that matters, these are all MyISAM tables without any foreign keys, and I ran the same queries on my dev machine and on the production server with the same result, so any corruption could remain mysqldump / source, which sounds awfully weird.
, , , , /?
!
Daniel