SQL Tutorial
What is SQL SQL SELECT SQL SELECT DISTINCT SQL WHERE SQL INSERT SQL UPDATE SQL DELETE SQL AND, OR & NOT Clause SQL ORDER BY SQL LIKE Clause SQL IN Operator SQL BETWEEN Operator SQL MAX() and MIN() SQL COUNTSQL JOIN
SQL JOIN SQL INNER JOIN SQL LEFT JOIN SQL RIGHT JOIN SQL FULL OUTER JOINSQL SELECT DISTINCT
This statement is use to select the distinct value or different value from the database.
In a Table, the column can contain or have same value(duplicate), so to get the unique value or different value we use distinct statement.
Syntax:
SELECT DISTINCT column1, column2 FROM table_name;
Example Database:
This is customer table. In this table, we are showing the customer details form the same location.
id | name | Location |
---|---|---|
1 | Kailash | Delhi |
2 | Amit | Haryana |
3 | Siddarth | Noida |
4 | Vikas | Noida |
SELECT DISTINCT Example:
The following SQL statement selects only the DISTINCT values from the location column in the customer table:
SELECT DISTINCT location FROM customer;
Result:
Location |
---|
Delhi |
Haryana |
Noida |
If you want to show, the number of different (distinct) customer location:
SELECT COUNT(DISTINCT location) FROM customer;
Result:
COUNT(DISTINCT location) |
---|
3 |
Elevenstech Web Tutorials
Elevenstech Web Tutorials helps you learn coding skills and enhance your skills you want.
As part of Elevenstech's Blog, Elevenstech Web Tutorials contributes to our mission of “helping people learn coding online”.
Read More
Newsletter
Subscribe to get the latest updates from Elevenstech Web Tutorials and stay up to date