MySQL Row Selection with NULL Value
In MySQL, users often encounter discrepancies between expected results and actual database contents when dealing with NULL values. A common issue arises when attempting to select rows where a specific column contains NULL but receiving an empty set as the outcome.
To resolve this dilemma, it's crucial to understand that NULL is treated as a distinct and special value in SQL. Unlike other data types, it cannot be equated to any other value, including itself. As per Rule 3 of Codd's 12 Rules, "NULL = NULL is always false."
Therefore, to correctly select rows where a column is NULL, the query syntax requires a different approach. Instead of using the "=" operator, the "IS NULL" syntax is necessary. For instance, instead of "userid = NULL," the query should be "userid IS NULL."
This ensures that the query accurately retrieves rows where the specified column explicitly contains NULL values. By adhering to this syntax, users can effectively identify and manipulate rows based on NULL values as intended.
The above is the detailed content of How to Select Rows with NULL Values in MySQL?. For more information, please follow other related articles on the PHP Chinese website!