-
SQL Installing SSMS
-
SQL Syntax
-
SQL Datatype
-
SQL Database
-
SQL Table
-
SQL Select
-
SQL Distinct
-
SQL Count
-
SQL Top
-
SQL Aliases
-
SQL In
-
SQL Insert
-
SQL Update
-
SQL Null
-
SQL Like
-
SQL Wildcards
-
SQL Nested Query
-
SQL Between
-
SQL Unique
-
SQL Primary Key
-
SQL Foreign Key
-
SQL Check
-
SQL Default
-
SQL Database Diagram
-
SQL Stored Procedures
-
SQL Joins
-
SQL Inner Join
-
SQL Left Join
-
SQL Right Join
-
SQL Full Join
-
SQL Trigger
SQL Select Distinct
The SQL DISTINCT command is used with the SELECT keyword to retrieve only distinct or unique data. In a table, there may be a chance to exist a duplicate value and sometimes we want to retrieve only unique values. In such scenarios, SQL SELECT DISTINCT statement is used.
Example:
SELECT DISTINCT column_name , column_name FROM table_name;
Let’s try to understand it by the table given below
Here is a table of students from where we want to retrieve distinct information For example: distinct home-town.
SELECT DISTINCT home_town FROM students;
Now, it will return two rows.
Course Video
1. Write a SQL query to get unique cities AND PostalCode from Person_Address table.
[OUTPUT: 24 ROWS]
2. Write a SQL query to get unique CountryRegionCode from Sales_SalesTerritory table.
[OUTPUT: 6 ROWS]
3. Write a SQL query to get unique JobTitle from HumanResources_Employee table.
[OUTPUT: 24 ROWS]
4. Write a SQL query to get unique Title from Person_Person table.
[OUTPUT: 3 ROWS]
5. Write a SQL query to get unique productID from Sales_SalesOrderDetail table.
[OUTPUT: 45 ROWS]
YouTube Reference :
1) SQL Select Distinct in Hindi/Urdu
2) SQL Select Distinct in English