
- 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 MySQL returns when we use DISTINCT clause with the column having multiple NULL values?
When we use the DISTINCT clause on a column having multiple NULL values then all the NULL values are treated as same by MySQL.
It means as per the properties of the DISTINCT clause, MySQL will return only one NULL value in the result set and eliminate the others. Consider the example of a table named ‘testing’ which have multiple NULL values in column ‘Lname’.
mysql> Select * from testing; +------+---------+---------+ | id | fname | Lname | +------+---------+---------+ | 200 | Raman | Kumar | | 201 | Sahil | Bhalla | | 202 | Gaurav | NULL | | 203 | Aarav | NULL | | 204 | Harshit | Khurana | | 205 | Rahul | NULL | | 206 | Piyush | Kohli | | 207 | Lovkesh | NULL | +-----+---------+----------+ 8 rows in set (0.00 sec) mysql> SELECT DISTINCT Lname from testing; +---------+ | Lname | +---------+ | Kumar | | Bhalla | | NULL | | Khurana | | Kohli | +---------+ 5 rows in set (0.00 sec)
From the query above, it can be seen that MySQL returns only one NULL and eliminate the others when we use the DISTINCT clause on the column ‘Lname’ having four NULL values.
- Related Articles
- Can we use MySQL GROUP BY clause with multiple columns like MySQL DISTINCT clause is used?
- How Can we use MySQL DISTINCT clause with WHERE and LIMIT clause?
- Can we fetch multiple values with MySQL WHERE Clause?
- How can we use MySQL SUM() function with HAVING clause?
- How to use MySQL DISTINCT clause on multiple columns?
- How MySQL evaluates if we use EXISTS operator with the subquery that returns NULL?
- When MySQL IN() function returns NULL?
- When MySQL MAKE_SET() function returns NULL?
- What MySQL returns if sub-query, used to assign new values in the SET clause of UPDATE statement, returns multiple rows?
- Update with multiple values in MySQL WHERE clause
- How to use MySQL LIKE clause to fetch multiple values beginning with “Joh”
- What happens when we apply NOT NULL constraint, with ALTER TABLE statement, to a column contains NULL values?
- How MySQL SUM() function evaluates if the column having NULL values too?
- When a MySQL arithmetic expression returns NULL?
- What MySQL COUNT() function returns if there are some NULL values stored in a column also?

Advertisements