Find Unique Emails
We can use the below keyword to find the list of unique values of a table column.
- DISTINCT, which returns a list of unique or distinct values of a column
Let's assume a table with the below table definition and data, where we need to find the unique emails.
id name email
===========================
1 Arun arun@example.com
2 Kiran kiran@example.com
3 James arun@example.com
4 Sammy sammy@example.com
5 Martin martin@example.com
SQL Query Using DISTINCT
SELECT DISTINCT email FROM employees;
This query returns the list of unique emails from the email column of the table.
SQL Query Using DISTINCT and WHERE
SELECT DISTINCT email FROM employees WHERE id IN (1,3,5);
This query returns a list of unique emails among the employees included based on the WHERE condition.
In this example, the WHERE condition includes the employees with id as 1, 3, and 5.
Overall
We now know the SQL Query to find a list of unique values from a specific table column.