When "NOT IN" in where clause gives unexpected/null result

Some time NOT IN condition in where clause gives you unexpected and null result in mysql.
So to avoid this use "where column name is not null" in subquery like the bold text in example below.


SELECT * FROM PatientsMigration 

WHERE LTRIM(RTRIM(nhinumber)) NOT  IN 

(SELECT LTRIM(RTRIM(nhinumber))  FROM patients WHERE nhinumber IS NOT null)

Comments

Popular posts from this blog

Grouping Sets, With Rollup and With Cube example

Adding Page brake aganist group values

To Get All the Names of tables and Databases their data have changed in last 24 Hours And Backup those databases