In MariaDB, NULL represents an unknown value in a column. This is not the same as an empty or zero string. Instead, it means that the actual data value is not in the database. This is especially important when dealing with optional data fields or unknown information. In this article, we will understand how the IS NULL condition can be used to query data in MariaDB.
IS NULL Operator
- The IS NULL condition is used to filter and retrieve rows where a certain column has NULL values.
- The IS NULL operator returns true if the expression is null.
Syntax:
SELECT field1, field2,… FROM table_name WHERE field_name IS NULL;
Queries Using the IS NULL Operator in MariaDB
Create Table
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
department_id INT,
salary DECIMAL(10, 2),
Hire_date DATE
);
Insert Data
INSERT INTO employees VALUES
(1, 'John', 'Doe', 3, 50000.00,'2022-01-15'),
(2, 'Jane', 'Smith', 2, 60000.00,'2022-02-20'),
(3, 'Bob', 'Johnson', 1, 75000.00,'2022-03-10'),
(4, 'Vivek', 'Sharma', 2, 65000.00,NULL),
(5, 'Minal', NULL, 1, 70000.00,'2022-03-10');
Query 1: Finding Rows With Null Values
SELECT employee_id, first_name, last_name FROM employees WHERE last_name IS NULL;
This query returns the first name, last name, and a list of employees whose last name is not specified as zero.
Output:
IS NULL Operator
Query 2: With DELETE Operator
DELETE FROM employees WHERE first_name IS NULL;
This will delete all the records from the employees table where first name is null.
Output:
IS NULL Operator
Query 3: With ORDER BY Clause
SELECT last_name FROM employees ORDER BY ISNULL(last_name), last_name;
This query will retrieve last names from the employee table, and the sorted results are sorted so that rows with NULL last names appear first with no rows with no zero last names sorted increasing order
Output:
IS NULL Operator
Query 4: With ORDER BY Clause
SELECT worker_id, first_name FROM worker WHERE Hire_date IS NULL;
This query will give you the list of worker id and first names from worker table whose hire date is null.
Output:
IS NULL Operator
Conclusion
Effective database management in MariaDB requires an understanding of handling NULL values. The IS NULL condition allows you to control unknown data by allowing you to filter and retrieve information based on missing values. You can create flexible and extensible database structures by using NULL in your queries, regardless of whether you are working with customer, employee, or order information.
Similar Reads
MySQL IS NULL Operator
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 understa
3 min read
Union Operator in MariaDB
MariaDB is an Open-Source Database system and MariaDB offers similar security features to MySQL, including access control, user authentication, and encryption. UNION operator is a fundamental part of MariaDB, a well-known database systeÂm. The UNION operator mergeÂs results from different SELECT que
5 min read
Intersect Operator in MariaDB
MariaDB, a popular open-source relational database management system (RDBMS), offers a plethora of powerful features for data manipulation and querying. Among these features is the Intersect operator, a valuable tool for performing set operations on query results. In this article, We will learn bout
4 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
Comparison Operator in MariaDB
In the world of database management, precise comparisons are essential for accurate data retrieval and manipulation. MariaDB, a powerful open-source relational database system, offers a range of comparison operators to help us filter and query our data effectively. In this article, We will learn abo
5 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
|| operator in Java
|| is a type of Logical Operator and is read as "OR OR" or "Logical OR". This operator is used to perform "logical OR" operation, i.e. the function similar to OR gate in digital electronics. One thing to keep in mind is the second condition is not evaluated if the first one is true, i.e. it has a sh
1 min read
MariaDB Procedure
MariaDB is an open-source database to help store and organize data. Itâs similar to other popular database software like MySQL but has some unique features and improvements. The MariaDB database is used for various purposes such as data warehousing, e-commerce, enterprise-level features, and logging
5 min read
Operators in SAP ABAP
High-level programming languages like SAP ABAP (Advanced Business Application Programming) are used to create apps in the SAP environment. Operators are essential for the execution of many different operations in SAP ABAP, ranging from straightforward arithmetic computations to complex logical analy
7 min read
MongoDB NOT operator ( $not )
In MongoDB, the $not operator is a logical query operator that allows us to negate or reverse the condition specified in a query. It plays a crucial role in filtering documents by excluding those that match a given expression. This powerful operator is often used with other comparison operators such
5 min read