SQL Distinct Keyword
Posted on
< Previous Next >
The DISTINCT keyword in SQL is used to return only distinct or unique values from a table column. This means that if we have multiple rows with the same value in a specific column, the DISTINCT keyword will only return one of those values.
SELECT DISTINCT Syntax
SELECT DISTINCT column1, column2, …
FROM table_name;
For example,
Let's say we have a table named "student" with columns "id", "name", "email", "phone", and "address". If we want to retrieve a list of unique email addresses from the "student" table,
We can use the following SQL statement:
SELECT DISTINCT email FROM student;
OUTPUT

In this above example,
This statement retrieves a list of unique email addresses from the "student" table. If there are multiple rows with the same email address, the DISTINCT keyword ensures that only one email address is returned in the result set.
It's important to note that the DISTINCT keyword is used in conjunction with the SELECT statement. We can use it with one or multiple columns to retrieve unique values from those columns.
< Previous Next >