As we learn before, SQL SELECT statement will allow us to call out all the data from particular table. What if we want to select distinct elements?
In SQL, DISTINCT keyword is used to return only distinct (different) values.All we need to do is add the DISTINCT after SELECT.
The SQL Syntax will look like this:
SELECT DISTINCT [COLUMN NAME] FROM [TABLE NAME]
The DISTINCT clause allows you to remove duplicates from the result set.
EXAMPLE :
Let�s say, we want to know departments from GameScores for people who participate.
Table GameScores
PlayerName | Department | Scores |
Jason | IT | 3000 |
Irene | IT | 1500 |
Jane | Marketing | 1000 |
David | Marketing | 2500 |
Paul | HR | 2000 |
James | HR | 2000 |
SQL statement :
SELECT DISTINCT Department FROM GameScores
This SQL statement would return all unique Department from the GameScores table
Result:
Department |
HR |
IT |
Marketing |