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 |
|
eem_2055
Yak Posting Veteran
69 Posts |
Posted - 2008-03-29 : 02:58:51
|
| Hi guys,I need your help! May I know what can I do to get a single name using the sample table below?toptablename accounta 1a 2a 3b 1b 2c 2d 3e 1e 2result will be toptablename accounta 1b 2c 2d 3e 2I just want to get all single names |
|
|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
Posted - 2008-03-29 : 03:06:21
|
| try this,Select Name, Min(Account) AS 'Account'From tblGroup By Name |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-03-29 : 03:06:31
|
| [code]SELECT name,MAX(account)FROM YourTableGROUP BY name [/code]OR [code]SELECT name,MIN(account)FROM YourTableGROUP BY name[/code]OR sql 2005 compatible soln.[code]SELECT t.name,t.accountFROM(SELECT ROW_NUMBER() OVER (PARTITION BY name ORDER BY NEWID() DESC) AS RowNo,name,accountFROM Table)tWHERE t.RowNo=1[/code] |
 |
|
|
eem_2055
Yak Posting Veteran
69 Posts |
Posted - 2008-03-29 : 03:22:23
|
| thanks a lot! :) |
 |
|
|
eem_2055
Yak Posting Veteran
69 Posts |
Posted - 2008-03-29 : 03:27:44
|
| but it gave the same result of records |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-03-29 : 03:42:32
|
| What do you mean? You still got duplicate names? If yes, can you post full query used? |
 |
|
|
eem_2055
Yak Posting Veteran
69 Posts |
Posted - 2008-03-29 : 03:44:17
|
| same nubmer of records |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-03-29 : 10:47:03
|
| Please post your full query used if you need more help. |
 |
|
|
|
|
|