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.
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, firstnameI 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 tablegroup by lastname,firstname orpost some sample data with expected resultMadhivananFailing to plan is Planning to fail |
 |
|
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.comJones Susie jones@heros.comskywalker Luke jetjock@universe.comZan Tar Tarzan@junglebook.comThe result I would like to see is jones@heros.comjetjock@universe.comtarzan@junglebook.comIn 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- |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-26 : 10:58:46
|
TrySelect min(email) as email from tablegroup by firstname orSelect min(email) as email from tablegroup by lastnameMadhivananFailing to plan is Planning to fail |
 |
|
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) |
 |
|
|
|
|