Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


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

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 Pro
 
Comment and Contribute

 

 

 

 

 


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

 

 

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