Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DISTINCT clause with WHERE

How can I use the DISTINCT clause with WHERE? For example:

SELECT * FROM table WHERE DISTINCT email; -- email is a column name 

I want to select all columns from a table with distinct email addresses.

like image 266
Mohit Avatar asked Apr 10 '11 08:04

Mohit


People also ask

What is distinct clause explain with suitable example?

Syntax. The DISTINCT clause is used to remove duplicate rows from the result set: SELECT DISTINCT column_list FROM table_name ; Here, column_list is a comma separated list of column or field names of a database table (e.g. name, age, country, etc.) whose values you want to fetch.

What is the distinct clause used for?

The SQL DISTINCT clause is used to remove duplicates from the result set of a SELECT statement.

WHERE value is distinct SQL?

SQL DISTINCT clause is used to remove the duplicates columns from the result set. The distinct keyword is used with select keyword in conjunction. It is helpful when we avoid duplicate values present in the specific columns/tables. The unique values are fetched when we use the distinct keyword.

Can we use distinct * in SQL?

The SQL SELECT DISTINCT StatementThe SELECT DISTINCT statement is used to return only distinct (different) values. Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.


1 Answers

If you mean all columns whose email is unique:

SELECT * FROM table WHERE email in      (SELECT email FROM table GROUP BY email HAVING COUNT(email)=1); 
like image 130
Adam Matan Avatar answered Oct 05 '22 20:10

Adam Matan