Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: SQL Server
Expertise: Beginner
Dec 14, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Selecting Rows Based on a Distinct Value

I have a table in my SQL 7 database that, among other values, contains e-mails. There are duplicate e-mail values in this table. I want to extract one record for each unique e-mail:
Select Distinct Email, *  From Entries
This doesn't work, but hopefully you can get the idea what I'm trying to do here.

How can I do this?

I think your issue is including the star in the query. Try pulling the distinct e-mails out by themselves first, as in:

select distinct e-mail, whatever_you_use_for_a_primary_key from entries into #temp
then you can collect the rest of the fields you want from ENTRIES by joining on the unique e-mails.
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date