Daily problem (1) - not in in Mysql will filter rows with null values

Conclusion: When using not in, you should pay attention to whether there is a null value in the field, because the null value row will be filtered out when using it

  1. When not in is used, it will filter the field to be null value row

  1. in will not count rows with null values, and will not be affected by null values

Reason: null value is fasle when compared with any value

Note: In addition to not in, "!=", "not like", etc. will also have this problem

Example:

1. To give a small example, the full amount of data is shown in the figure below.

SELECT * from temp;

2. If you want to filter out the data with score=70, you can write it in the following way, and the row whose score is null in the result will be filtered out.

SELECT * from temp where score not in (70);
In summary, when using not in, pay attention to the problem of null value. There are many solutions, such as: add a condition or the field is null, or convert it into a field that is not null in the table and use not in, or use in to query the data and then use the primary key Filtering can also wait.

Guess you like

Origin blog.csdn.net/qq_37764320/article/details/129144523