Overview

Distinct Statement is used to find out the distinct values in any of the columns.

Syntax

Syntax for Distinct Statement is

SELECT DISTINCT column_name FROM table_name;

Example

Let us get a clear picture with the help of an example

Consider table hostel_list containing the list of hostels

+----+-------------------+-----------+----------+
| id | name | occupancy | capacity |
+----+-------------------+-----------+----------+
|  1 | ASHOK BHAVAN | 2 | 1090 |
|  2 | KAILASH BHAVAN | 2 | 990 |
|  3 | RUDRAKSH BHAVAN | 2 | 990 |
|  4 | KAVERI BHAVAN | 1 | 690 |
|  5 | BHAGIRATHI BHAVAN | 4 | 2140 |
|  6 | NARMADA BHAVAN | 6 | 3240 |
|  7 | GANGA BHAVAN | 1 | 780 |
|  8 | YAMUNA BHAVAN | 8 | 4580 |
+----+-------------------+-----------+----------+

And suppose you want to fetch what distinct type of occupancy hostels have, Than you can run the following SQL Query

SELECT DISTINCT occupancy FROM hostel_list;
+-----------+
| occupancy |
+-----------+
|         2 |
|         1 |
|         4 |
|         6 |
|         8 |
+-----------+



If you want to add more comments to the article or you see any thing incorrect please write a comment below and we will surely get back to you.



Trending Articles


Incorrect table definition there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

Web Server vs Application Server Difference Explained

Infix To Postfix Conversion Using Stack in Javascript

SQL Overview

Binary Search Tree Insert node Implementation in Javascript

Evaluate Postfix Expressions Using Stack In Javascript

Linked List Size or Count in Javascript

MYSQL Dump - How to take mysql dump or export mysql data