Skip to content
Advertisement

DISTINCT for only one column

Let’s say I have the following query.

How can I modify it so that it returns no duplicate Emails?

In other words, when several rows contain the same email, I want the results to include only one of those rows (preferably the last one). Duplicates in other columns should be allowed.

Clauses like DISTINCT and GROUP BY appear to work on entire rows. So I’m not sure how to approach this.

Advertisement

Answer

If you are using SQL Server 2005 or above use this:

EDIT: Example using a where clause:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement