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: 559
Points: 1,008
Location: GB

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: 113
Points: 339
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
Index on a table
Business development
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.

Fantora Blog | Discount Shop UK | Discount Shop USA | Discount Shop Canada | Discount Boutique France | Discount Shop Deutschland | Discount Shop Italia | Descuento Shop España

Free Classified ads, Webmaster Forum & Technology Reviews | Fantora Free Classified Ads | Buy & Sell Electronics, Mobile phones & Accessories | fantora Forums Community | Buy & Sell DVD, Games and Consols | Free eBooks & Softwares | SEO & Affiliate Marketing Discussion | Programming Language Forum (.NET, ASP, PHP, SQL) | Free Classified Ads | General Stuff (Movies, Chat, Comics) | Free Online English Movies & Reviews | Free Online Hindi Movies & Reviews | Australia & New Zealand Immigration Forum | Europe immigration forum | Canada Immigration Forum | Ireland Immigration Forum | US Immigration Forum | United Kingdom Immigration Forum

Main Forum RSS : RSS

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