Wednesday 29 May 2013

NULL Condition in SQL


  1. IS NULL
  2. IS NOT NULL
NOTES:
  • The NULL conditions includes the IS NULL condition and IS NOT NULL conditions.
  • The IS NULL conditions tests for nulls.
  • A null value means the value is unavailable, unassigned, unknown or inapplicable. (null and zero both are different)
  • Therefore, you cannot test with = because a null cannot be equal or unequal to any value.


Example:
The above example retrieves the last names and managers of all employees who do not have a manager.

Example:
To retrieve the names, salary of employees who don't receive commission we can write the query like:


Example:

The above example shows the name,sal and commission of employees who commission is not null, i.e.
the employee receives commission, it may be zero but not null.

So, remember: null and zero both are different. 


No comments:

Post a Comment