Selecting Rows Based on a Distinct Value

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.

See also  How IoT Tech Will Transform Logistics

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist