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 |
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-----UserNameABC--------ABC UserABC--------ABC UsersHow 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 |
|
|
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 |
|
|
|
|
|