Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 using distinct

Author  Topic 

delpi767
Starting Member

11 Posts

Posted - 2007-10-26 : 10:20:22
This seems simple but it eludes me.

Given a table with the fields email, lastname, firstname

I want to create a query that returns distinct email addresses and is ordered by lastname, firstname.

Any help is appreciated.

Regards,

-dmd-

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-26 : 10:24:31

Select min(email) as email, lastname,firstname from table
group by lastname,firstname

or

post some sample data with expected result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

delpi767
Starting Member

11 Posts

Posted - 2007-10-26 : 10:47:37
suppose I have 4 records in the table two of which have duplicate email addresses -

Jones Indiana jones@heros.com
Jones Susie jones@heros.com
skywalker Luke jetjock@universe.com
Zan Tar Tarzan@junglebook.com

The result I would like to see is

jones@heros.com
jetjock@universe.com
tarzan@junglebook.com

In other words, I want the email addresses ordered by last name but I don't want to duplicate any of the email addresses.

Thanks,

Regards,

-dmd-
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-26 : 10:58:46
Try

Select min(email) as email from table
group by firstname

or



Select min(email) as email from table
group by lastname

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Reporter
Starting Member

48 Posts

Posted - 2007-10-30 : 10:44:27
select email from table group by email order by max(lastname)

Is this suitable query for your needs?

Also you may try this more wide query.

select email,person=max(lastname+' '+firstname)
from table group by email order by max(lastname+' '+firstname)
Go to Top of Page
   

- Advertisement -