0

I don't know how does MySQL works internally, but I'm sure there are some problem with indexes or some metainformation about table counts:

mysql> select count(*) from Event;
+----------+
| count(*) |
+----------+
|     5925 |
+----------+
1 row in set (0,01 sec)

mysql> select count(*) from Event where event_id in (select discount_event_id from Discount);
+----------+
| count(*) |
+----------+
|     5901 |
+----------+
1 row in set (0,12 sec)

mysql> select count(*) from Event where event_id not in (select discount_event_id from Discount);
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0,11 sec)

These 24 missing event_ids makes no sense. It's just logically impossible from my point of view. There cannot be 24 rows that both are and aren't in another set. Or they are, or they aren't.

Also, as suggested from some of the answers and comments, there are no NULL event_ids, since these are the rowids:

mysql> select count(*) from Event where event_id is null;
+----------+
| count(*) |
+----------+
|        0 |
+----------+

What is going on?

Peregring-lk
  • 9,685
  • 6
  • 44
  • 90

1 Answers1

4

It means there are 24 event_id that are NULL

select count(*) from Event where event_id IS NULL

both in and not in operators return NULL when you compare with NULL value, which is coerced to FALSE hence omitted from both result sets.

zerkms
  • 240,587
  • 65
  • 429
  • 525
  • There'are no `NULL` `event_id`s since that field is the rowid of the `Event` table. See the update on the question. – Peregring-lk Feb 01 '19 at 00:28