I have an app that receives an object and generates a dynamic query for gathering reporting data. That object contains filter properties that eventually translate into "WHERE" statements in MySQL. A simpler and on topic version of the generated query looks something like this:
SELECT cr3.id AS col_1,
count(table1.ids) AS col_2
FROM table1
LEFT JOIN table2 cr3 ON table1.id = cr3.Id
WHERE cr3.id NOT IN ('val') GROUP BY 1;
The Queried DB has this dataset (without any filtering applied):
| col_1 | col_2 |
| null | 100 |
| val | 100 |
When that's executed the result set is empty. I was expected to get the first row of the dataset:
| null | 100 |
If I adjust there WHERE clause from
WHERE cr3.id NOT IN ('val') => WHERE (cr3.id NOT IN ('val') OR cr3.id IS NULL)
I receive the expected results, but this is dynamically generated for different types of queries and I can't find anyway to tweak the "NOT IN" operator to have a proper behavior and return everything that doesn't match what's specified as an argument.
Any Ideas ?