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 2000 Forums
 Transact-SQL (2000)
 Sql select

Author  Topic 

shah
Starting Member

5 Posts

Posted - 2007-06-14 : 04:22:01
Hi,

i need help regarding how to select the replicate values from table


i have a table which consist
sno name
1 saam
2 john
3 saam
4 saam
5 john
6 smith
7 shelly
8 smith

from this i just want to get the repeated values i.e
sno name
1 saam
2 john
3 saam
4 saam
5 john


can any one help out how to get this

i have tried with group by n having clauses but no result.


thanx in advance


shah

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-06-14 : 04:34:22
Select * from <table> where name in
(Select name
from <table>
group by name
having count(*) > 1)

--------------------------------------------------
S.Ahamed
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-14 : 04:34:47
[code]select t.sno, t.name
from table t
inner join
(
select name
from table
group by name
having count(*) > 1
) d
on t.name = d.name[/code]


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-14 : 04:35:27
25 secs


KH

Go to Top of Page

shah
Starting Member

5 Posts

Posted - 2007-06-14 : 05:35:45
thanx a lot its working
quote:
Originally posted by pbguy

Select * from <table> where name in
(Select name
from <table>
group by name
having count(*) > 1)

--------------------------------------------------
S.Ahamed




shah
Go to Top of Page

shah
Starting Member

5 Posts

Posted - 2007-06-14 : 06:45:03
Thanx a lot this query is working

quote:
Originally posted by khtan

select t.sno, t.name
from table t
inner join
(
select name
from table
group by name
having count(*) > 1
) d
on t.name = d.name



KH





shah
Go to Top of Page
   

- Advertisement -