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
 General SQL Server Forums
 New to SQL Server Programming
 Need to fetch record from table with some cond?

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....

TableA
colA ColsB ColC
111 22222 3333
111 ggjgj sfsa
123 fdfdf 2323
111 33333 defd

I need to fetch the all the columns from this table but the the o/p table should resemble like below.....
111 22222 3333
123 fdfdf 2323

Note : I want to discard the duplicate records from ColA with considering the other column values....

Please help me to resolve this issueee.....

Thanks In Advance

Thanks,
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.
Go to Top of Page

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 sfsa
111 33333 defd
Go to Top of Page

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 sfsa
111 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.
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-12-22 : 10:40:11
try this

declare @temp table (cola int,colb varchar(30),colc varchar(30))

insert into @temp
select 111, '22222', '3333' union all
select 111, 'ggjgj', 'sfsa' union all
select 123, 'fdfdf', '2323' union all
select 111, '33333', 'defd'

select * from @temp

select 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
Go to Top of Page

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
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -