Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
MySQL EXCEPT Operator
Next article icon

MySQL IS NULL Operator

Last Updated : 23 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The IS NULL operator in MySQL is a powerful tool for handling records with missing or incomplete data. It enables precise querying and data management by allowing users to identify and act upon fields where values are absent.

In this article, We will learn about the MySQL IS NULL Operator by understanding various examples and so on.

MySQL IS NULL Operator

  • The IS NULL operator in MySQL efficiently identifies and manages records with missing or incomplete data.
  • It supports accurate queries and data integrity.
  • It Facilitates complex querying scenarios by allowing conditions based on the presence or absence of values.
  • It Helps to maintain clean and accurate data by enabling checks for incomplete records.

Syntax

The IS NULL operator is used in SQL queries to test whether a column value is NULL. The basic syntax for using IS NULL is:

SELECT column1, column2, ...

FROM table_name

WHERE column_name IS NULL;

Examples of MySQL IS NULL

Example 1: IS NULL with SELECT Statement

Consider a table named orders with the following structure:

CREATE TABLE orders (

order_id INT PRIMARY KEY,

customer_name VARCHAR(50),

order_date DATE,

shipping_date DATE

);

Inserting sample data into the orders table:

INSERT INTO orders (order_id, customer_name, order_date, shipping_date) VALUES

(1, 'Alice', '2024-07-01', NULL),

(2, 'Bob', '2024-07-02', '2024-07-05'),

(3, 'Charlie', '2024-07-03', NULL),

(4, 'Dana', '2024-07-04', '2024-07-06');

Output:

45


To retrieve records where the shipping_date is NULL:

SELECT order_id, customer_name, order_date

FROM orders

WHERE shipping_date IS NULL;

Output:

io

This result shows orders that have not been shipped yet, as their shipping_date is NULL.

Example 2: IS NULL with COUNT() Function

To count the number of orders that have not been shipped:

SELECT COUNT(*)

FROM orders

WHERE shipping_date IS NULL;

Output:

78

This output indicates that there are 2 orders with a NULL shipping_date.

Example 3: IS NULL with UPDATE Statement

To update the shipping_date for orders that have not been shipped yet:

UPDATE orders

SET shipping_date = '2024-07-10'

WHERE shipping_date IS NULL;

Output:

After executing this query, the table orders will be updated. To view the changes, you can run:

SELECT * FROM orders;

Updated Table Data:

41

This result shows that the shipping_date for the orders with order_id 1 and 3, which previously had NULL values, has been updated to '2024-07-10'.

Example 4: IS NULL with DELETE Statement

To delete records where the shipping_date is NULL:

DELETE FROM orders

WHERE shipping_date IS NULL;

After running the delete statement, to view the remaining records:

SELECT * FROM orders;

Output:

52

This result shows that the orders with NULL shipping_date have been deleted from the table.

Conclusion

Overall, IS NULL operator is very useful in searching for records in which one or several fields may not have any data. As in this case, the procedures using IS NULL helps in finding the order that has not been shipped. This capability is essential when handling needed data as well as in cases when some operations require the absence or presence of data in certain columns.


Next Article
MySQL EXCEPT Operator

A

amit7822i5n
Improve
Article Tags :
  • Databases
  • MySQL

Similar Reads

  • MySQL EXISTS Operator
    The EXISTS operator in MySQL is a powerful boolean operator used to test the existence of any record in a subquery. It returns true if the subquery yields one or more records, enabling efficient data retrieval and manipulation, particularly in large datasets. The operator is often paired with subque
    6 min read
  • SQL IS NOT NULL Operator
    In SQL, the IS NOT NULL operator is a powerful logical operator used to filter data by identifying rows with non-NULL values in specified columns. This operator works opposite to the IS NULL operator, returning TRUE for rows where the value is not NULL. It is typically used with the WHERE clause and
    5 min read
  • MySQL NOT EQUAL Operator
    SQL (Structured Query Language) is a powerful language used for managing and manipulating relational databases. It provides a standardized language for querying the databases which are found to be structured, allowing users to define, manipulate, and control the data retrieval with ease. SQL operate
    4 min read
  • PL/SQL IS NULL Operator
    The IS NULL operator is a fundamental tool in PL/SQL used to determine the presence of NULL values in database columns. Understanding how to effectively use the IS NULL operator is crucial for database management, as it allows developers and analysts to identify and handle records with missing or un
    4 min read
  • MySQL EXCEPT Operator
    Comparison of two different sets of data in a database and finding entries unique to one set is one of the common operations done on databases. The EXCEPT operator in SQL compares the two result sets returned and returns only the rows that are found in one but not the other. Moreover, MySQL, one of
    6 min read
  • MySQL UNION Operator
    Database management is an important concept of handling and organizing data effectively. One powerful Operator in MySQL for combining results from multiple queries is the UNION operator. This operator allows you to merge the results of two or more SELECT statements into a single result set, eliminat
    4 min read
  • MySQL ANY and ALL Operators
    When working with databases, there are often scenarios where we need to compare a value against multiple other values. MySQL offers two powerful operators for this purpose such as ANY and ALL Operators. These operators allow for more complex and flexible data retrieval, enabling comparisons between
    5 min read
  • SQL NOT EQUAL Operator
    The SQL NOT EQUAL operator is a comparison operator used to check if two expressions are not equal to each other. It helps filter out records that match certain conditions, making it a valuable tool in SQL queries. In this article, We will explore the SQL NOT EQUAL operator, including its syntax, us
    4 min read
  • SQL NOT IN Operator
    The NOT IN operator in SQL is used to exclude a specified set of values in a query, making code more readable and efficient. It is often combined with SELECT, UPDATE, and DELETE statements to filter out rows that match any value in a given list. This operator is a more intuitive alternative to using
    4 min read
  • SQL IN Operator
    The SQL IN operator filters data based on a list of specific values. In general, we can only use one condition in the Where clause, but the IN operator allows us to specify multiple values. In this article, we will learn about the IN operator in SQL by understanding its syntax and examples. IN Opera
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences