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)
 An easy query

Author  Topic 

oepirobo
Starting Member

36 Posts

Posted - 2003-03-06 : 15:04:45
I have this table:

FirstName LastName City State
------------------------------------------
Al Bundy Chicago Ill
Peg Bundy Gary Ind
Johnathan Davis LA Cal
Del Davis Omaha Neb
Geena Davis Seattle Was

I need to see all fields but only one row per last name, so I would only see:

FirstName LastName City State
------------------------------------------
Al Bundy Chicago Ill
Johnathan Davis LA Cal

How do I do this?

nr
SQLTeam MVY

12543 Posts

Posted - 2003-03-06 : 17:39:52
What is the PK?
If it's FirstName, LastName

select t1.*
from tbl t1
where t1.FirstName = (select min(t2.FirstName) from tbl t2 where t1.LastName = t2.LastName)

But you probably have an id or guid so use that for the subquery join.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -