devxlogo

Selecting Rows Based on a Distinct Value

Selecting Rows Based on a Distinct Value

Question:
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?

Answer:
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-admin

Share the Post: