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
 SQL Server Development (2000)
 Getting one record on a grouping same ID diff desc

Author  Topic 

jgandara
Starting Member

18 Posts

Posted - 2005-09-02 : 11:12:44
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

3467 Posts

Posted - 2005-09-02 : 11:25:39
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

Go to Top of Page

jgandara
Starting Member

18 Posts

Posted - 2005-09-02 : 11:42:55
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
   

- Advertisement -