Wednesday, December 18, 2024

SQL IS NOT NULL Keyword

 In SQL, the IS NOT NULL keyword is used to filter out rows where a specified column has a NULL value. This is commonly used in WHERE clauses to ensure that only records with non-null values are selected.

Example:

SELECT * 
FROM employees
WHERE salary IS NOT NULL;

In this query, the IS NOT NULL condition filters the employees table to return only those rows where the salary column has a value (i.e., it is not NULL).

Usage:

  • IS NOT NULL is typically used when you want to exclude NULL values from the result.
  • It is often paired with WHERE or HAVING clauses to filter rows based on whether a column contains a value.

Key Points:

  • NULL represents the absence of a value or an unknown value.
  • IS NOT NULL checks that the column has some value, not NULL.
  • IS NOT NULL cannot be used with comparison operators (like =, <, etc.), because NULL is not a value but an unknown state. Therefore, IS NOT NULL is the correct way to check for non-null values.

No comments:

Post a Comment