Follow Fantora on Twitter
Fantora Word of Classified Ads and Community Forum
Welcome Guest Search | Active Topics | Members | Log In | Register

how to check duplicate rows in tableof sql server

Options
ca4nul
Posted: Monday, February 02, 2009 8:05:59 AM
Rank: Advanced Member
Groups: Member

Joined: 11/9/2007
Posts: 489
Points: 1,042
Location: UK

how to check duplicate rows in tableof sql server

hi all

i dont have primary key on one of my table. i want to check duplicate rows in table and further want to remove them

thanks
hari
Posted: Monday, February 02, 2009 8:08:40 AM
Rank: Advanced Member
Groups: Member

Joined: 3/31/2008
Posts: 94
Points: 282
Location: London

how to check duplicate rows in tableof sql server

ca4nul wrote:
hi all

i dont have primary key on one of my table. i want to check duplicate rows in table and further want to remove them

thanks



// Return all duplicate cities and how often they appear
// Works with ORACLE

Code:
select city_name, count(city_name) as cnt
from areas
group by city_name
where cnt>1



// not all SQL dbms will support the reference to the count column cnt in the where clause.
// The following will return ALL rows with counter, but sorted by number of appearances
// Your duplicates will be at the top.
// Works with MYSQL

Code:
select city_name, count(city_name) as cnt
from areas
group by city_name
order by cnt desc



// finally, no back reference to count column cnt at all-
// the following will work on all SQL dbms:
// Return all cities and how often they appear

Code:
select city_name, count(city_name) as cnt
from areas
group by city_name


// version for Micrsoft's MSSQL Server
// make use of the HAVING clause

Code:
select city_name
from areas
group by city_name
having count(*) > 1


Users browsing this topic
Guest

 Related
Business development
In defence of SQL
TV: Navy NCIS episode.
Integration Solutions Possible without writing Codes
Innovative Enterprise Application Integration
Upcoming Webinar: Reduce IT infrastructure costs using Application Portfolio Management
Highly configurable and extensible Dataflow architecture
Upcoming Webinar: Best Practices and Proven Techniques for Application Portfolio Management
Recorded Webinar: Data Management Challenges for Govt Applications
Elegant dataflow solution
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

Powered by: YAF.NET
Copyright © AI Logica All rights reserved.
This page was generated in 0.122 seconds.