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
 count in where condition ?

Author  Topic 

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-07-07 : 06:24:54
Hi

I have col1 in a table like below

Col1-----Col2------Col3
123-------kj--------tuu
254-------etr--------keu
233-------fda--------you
233-------da--------hgju
233-------rte--------kju

I am trying to get like below

select col1,col2,col3 From tbl where count(col1) > 1

Advanc Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-07 : 06:28:53
select col1,col2,col3 From tbl where col1 in
(select col1 from tbl group by col1 having count(col1) > 1
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-07-07 : 06:30:44
[code]declare @t table
(
col1 int,
col2 varchar(10),
col3 varchar(10)
)

insert @t
select 123, 'kj', 'tuu' union all
select 254, 'etr', 'keu' union all
select 233, 'fda','you' union all
select 233, 'da','hgju' union all
select 233, 'rte','kju'

select *
from @t t1
join
(select col1 from @t group by col1 having count(*) > 1) t2
on t1.col1 = t2.col1[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-07-07 : 07:06:15
Hi

Thanks a lot guys
Go to Top of Page
   

- Advertisement -