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 2005 Forums
 Transact-SQL (2005)
 Unique records

Author  Topic 

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2010-04-01 : 03:06:06
I want to select records where col1=@val1 [records should have different col2 or col3 with same col1 ]
Eg.
col1 col2 col3
111 aa s1
111 aa s2
111 bb s1

tks.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-01 : 03:30:44
what is the expected result ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2010-04-01 : 03:39:35
Below is the expected result
col1 col2 col3
111 aa s1
111 aa s2
111 bb s1
Out of
col1 col2 col3
111 aa s1
111 aa s2
111 bb s1
111 aa s1
111 bb s1

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-01 : 03:45:47
Then you can use group by.
select col1,col2,col3
from table
group by col1,col2,col3


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2010-04-01 : 03:48:36
I also have other cols to be selected.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-01 : 03:59:20
quote:
Originally posted by kwikwisi

I also have other cols to be selected.


then add it to the select and group by list

if this is not what you are after, perhaps you should take one step back and explain your situation and requirement


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -