- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why we cannot use comparison operator(=) for getting the rows with NULL from a table?
152 Lectures 16 hours
87 Lectures 5.5 hours
We cannot use = (comparison operator) because we know that NULL is not a value. If we want to get the rows with NULL from a table then we need to use IS NULL operator in MySQL query. Following example using the data from ‘employee’ table will exhibit it −
mysql> Select * from Employee WHERE Salary IS NULL; +----+-------+--------+ | ID | Name | Salary | +----+-------+--------+ | 7 | Aryan | NULL | | 8 | Vinay | NULL | +----+-------+--------+ 2 rows in set (0.00 sec)
The query above use IS NULL operator and produces the output where salary column is having NULL.
mysql> Select * from employee where salary = NULL; Empty set (0.00 sec)
The query above use = (Comparison operator) hence produces the empty set because with NULL is not a value.
- Why we cannot use MySQL DATE data type along with time value?
- Why do we use comma operator in C#?
- Why in MySQL, we cannot use arithmetic operators like ‘=’, ‘<’ or ‘<>’ with NULL?
- How MySQL evaluates if we use EXISTS operator with the subquery that returns NULL?
- What is MySQL NULL-safe equal operator and how it is different from comparison operator?
- How to use comparison operator for numeric string in MySQL?
- Can we use the word user for a MySQL table?
- How MySQL evaluates if we use EXISTS operator with a subquery that returns no rows?
- How can we delete multiple rows from a MySQL table?
- How can we delete all rows from a MySQL table?
- Fetch random rows from a table with MySQL
- Will “create table table” work in MySQL since we cannot use reserved words as table name?
- How can we use MySQL TRIM() to remove the whitespaces from all the rows and update table?
- Why do we check for a NULL pointer before deleting in C/C++?
- How to use MySQL SOUNDEX() function with LIKE operator to retrieve the records from table?