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 |
|
vinoth124
Starting Member
4 Posts |
Posted - 2008-12-22 : 10:24:17
|
| Hi Friends,Actually I need to fetch record from a table..... For example, consider the following as the table....TableAcolA ColsB ColC111 22222 3333111 ggjgj sfsa123 fdfdf 2323111 33333 defdI need to fetch the all the columns from this table but the the o/p table should resemble like below.....111 22222 3333123 fdfdf 2323Note : I want to discard the duplicate records from ColA with considering the other column values....Please help me to resolve this issueee.....Thanks In AdvanceThanks,Vinoth R |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-12-22 : 10:29:47
|
Can you explain how to decide which row is to retrieve and which rows to treat as duplicates?What SQL Server Version (2000 or 2005 or 2008)?Webfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-12-22 : 10:30:47
|
On what basis did you decide to discard these 2 rows ?111 ggjgj sfsa111 33333 defd |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-12-22 : 10:35:23
|
quote: Originally posted by sakets_2000 On what basis did you decide to discard these 2 rows ?111 ggjgj sfsa111 33333 defd
That was exactly my question - thx for clearing my description Webfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-12-22 : 10:40:11
|
| try thisdeclare @temp table (cola int,colb varchar(30),colc varchar(30))insert into @temp select 111, '22222', '3333' union allselect 111, 'ggjgj', 'sfsa' union allselect 123, 'fdfdf', '2323' union allselect 111, '33333', 'defd'select * from @tempselect t.cola,t.colb,t.colc from ( select row_number() over ( partition by cola order by cola ) as sno ,cola,colb,colc from @temp ) t where t.sno= 1 |
 |
|
|
vinoth124
Starting Member
4 Posts |
Posted - 2008-12-22 : 11:00:21
|
| I want to fetch all the column details but the condition is I need to get unique value for ColA.... In case if the table contains more than one value for ColA then I need to fetch any one from that....Thanks,Vinoth R |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-12-22 : 11:08:12
|
In this case and if you have SQL Server > 2000 try rakys solution.Webfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|