crishenrique1986
crishenrique1986

Reputation: 21

Database SQL Select Distinct

I need to show all information from all columns in the table, but filter so that all records that occurred in the duplicate email will be discarded one and keep the other one so that there is no duplication.

Example before the filter:

Name 1 | City 1 | Email 1
Name 2 | City 2 | Email 2
Name 3 | City 3 | Email 1

After the filter should display as follows:

Name 1 | City 1 | Email 1
Name 2 | City 2 | Email 2

Record 3 was disregarded because it has the same e-mail (duplicate) as record 1.

Upvotes: 2

Views: 45

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269463

You can use row_number():

select t.*
from (select t.*,
             row_number() over (partition by email order by email) as seqnum
      from t
     ) t
where seqnum = 1;

Upvotes: 1

Related Questions