SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
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
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jgandara
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:
UserId-----UserName
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

SamC
White Water Yakist

USA
3459 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

jgandara
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  
 New 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.06 seconds. Powered By: Snitz Forums 2000