December 12, 2007 at 7:49 am
Good morning, everyone.
Assuming the following table:
Email Fname
==== =====
sales@abc.com Bob
sales@abc.com Sally
marketing@zyx.net Rick
marketing@zyx.net Robby
What SELECT statement would I run to return only 1 row from the above table, for each distinct value in the Email field? I.e. I only want my query to return two rows, one for sales@abc.com and one for marketing@zyx.net. It doesn't matter which value from FName is returned.
Thanks in advance for any help or info,
- Simon Doubt
December 12, 2007 at 7:52 am
select Email,max(Fname) as Fname
from mytable
group by Email
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537December 12, 2007 at 7:56 am
Using the distinct won't work since you have different fnames for each email address...
you'll have to group by email address, and choose an aggregate function for the fname (min, max...)
Select Email_address, min(fname) from your_table group by emailAddress.
December 12, 2007 at 7:59 am
Terrific - thank you, Mark and jghali for you input.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply