
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
What is the operator <=> in MySQL?
Here are the usages of the <=> operator in MySQL.
Case 1
This operator is similar to = operator i.e. when the value is equal then the result will become true(1), otherwise false(0).
In the first case both = and <=> operators work same.
Case 2
Whenever we compare any value with NULL then the <=> operator gives the value 0 and when we compare with NULL <=> NULL, then it returns 1.
While in case of = operator, this does not happen. Whenever we compare any value with NULL, it returns NULL. If we compare NULL with NULL, then only NULL is returned.
Here is an example for both the cases discussed above. The query is as follows −
mysql> SELECT 10 <=> 10, NULL <=> NULL, 10 <=> NULL;
Here is the output.
+-----------+---------------+-------------+ | 10 <=> 10 | NULL <=> NULL | 10 <=> NULL | +-----------+---------------+-------------+ | 1 | 1| 0| +-----------+---------------+-------------+ 1 row in set (0.00 sec)
Look at the above output, NULL <=> NULL returns 1, not NULL.
Let us now see an example for = operator. The query is as follows −
mysql> SELECT 10 = 10, NULL = NULL, 10 = NULL;
Here is the output.
+---------+-------------+-----------+ | 10 = 10 | NULL = NULL | 10 = NULL | +---------+-------------+-----------+ | 1 | NULL | NULL | +---------+-------------+-----------+ 1 row in set (0.00 sec)
Look at the above output, NULL = NULL returns NULL.
- Related Articles
- What is the use of RLIKE operator in MySQL?
- What is the use of SOUNDS LIKE operator in MySQL?
- What is the use of MySQL NOT LIKE operator?
- What is the use of MySQL SOUNDS LIKE operator?
- What is the use of MySQL IS and IS NOT operator?
- What is the difference between MySQL ISNULL() function and IS NULL operator?
- What is MySQL NULL-safe equal operator and how it is different from comparison operator?
- What is the difference Between AND, OR operator in MySQL while Retrieving the Rows?
- What is the ?-->? operator in C++?
- What is the significant difference between MySQL LIKE and equal to (=) operator?
- Using ! operator in MySQL
- What is the conditional operator ?: in Java?
- What is the operator precedence in C#?
- What is the $unwind operator in MongoDB?
- What is the use of EXIST and EXIST NOT operator with MySQL subqueries?
