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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Getting one record on a grouping same ID diff desc
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

18 Posts

Posted - 09/02/2005 :  11:12:44  Show Profile  Reply with Quote
I have a table that stores user id and name on every record.Usually the name can change with time, so I have a query that groups by id and name, but instead of 1 records I get 2 or more.i.e:
ABC--------ABC User
ABC--------ABC Users

How can I get only one record by userid, no matter which one?

I get the user name from another database, which can be deleted, so I need to keep this info to be available in my app for historical reasons

White Water Yakist

3467 Posts

Posted - 09/02/2005 :  11:25:39  Show Profile  Reply with Quote
You have multiple records per UserID. Which UserName do you want?

If it doesn't matter...

SELECT UserID, MIN(UserName) As UserName FROM MyTable GROUP BY UserID

Edited by - SamC on 09/02/2005 11:29:26
Go to Top of Page

Starting Member

18 Posts

Posted - 09/02/2005 :  11:42:55  Show Profile  Reply with Quote
It was in front of my nose, I didn't think about grouping using Min or Max with varchar fields.

It worked thank you
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000