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
 query help

Author  Topic 

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2007-06-14 : 01:29:42
Dear experts,
I've one table...
there are somany repeated rows.

i can find the distinct rows using distinct command.

but how can i find the repeated rows?


please guide me in this regard.

Vinod
Even you learn 1%, Learn it with 100% confidence.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-14 : 01:38:31
[code]select col1, col2, ..., coln
from table
group by col1, col2, ..., coln
having count(*) > 1[/code]

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

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2007-06-14 : 01:46:00
thank you harsh

Vinod
Even you learn 1%, Learn it with 100% confidence.
Go to Top of Page

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2007-06-14 : 02:18:33
Dear harsh,
I'm not getting all the records....
suppose there are 5 records having same data, then the five records should be displayed...

Vinod
Even you learn 1%, Learn it with 100% confidence.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-14 : 02:23:03
What's the use of displaying five records if all of them have exactly same data.

Anyway, it can be done like this:

select t1.* from table t1 JOIN
(select col1, col2, ..., coln
from table
group by col1, col2, ..., coln
having count(*) > 1
) t2
On t1.col1 = t2.col1 and t1.col2 = t2.col2 .... and t1.coln = t2.coln


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

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2007-06-14 : 05:32:15
Thank you harsh....
actually for practice purpose i've asked the query

Vinod
Even you learn 1%, Learn it with 100% confidence.
Go to Top of Page
   

- Advertisement -