Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2004, 08:27 AM
Authorized User
 
Join Date: Apr 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default How find duplicates when I have several columns?

Hello,

How can I check if i have duplicates with a SQL-question when I have a table like this. Lets say the columns are integer and there are no unique index set on them and there are no primery key.

col1 col2
1 1
1 1


What I would like is something like this question does, but here it is only one column to check for duplicates.

select id, count(id) as Sum
from tabell
group by id
having count(id) > 1

So the result from the two columns above would be something like this
col1 col2 Sum
1 1 2

Thanks in advance
// Boson



 
Old October 15th, 2004, 08:44 AM
Authorized User
 
Join Date: Apr 2004
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just add rows to the SELECT and GROUP BY clauses

Code:
SELECT col1, col2, COUNT(*) as Sum
  FROM table
 GROUP BY col1, col2
HAVING count(*) > 1
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC





Similar Threads
Thread Thread Starter Forum Replies Last Post
removing duplicates havey C# 9 February 26th, 2008 02:05 PM
Yes to duplicates MMJiggy62 Beginning VB 6 3 July 14th, 2006 11:51 AM
eliminate duplicates in selected columns Callie SQL Server 2000 3 April 29th, 2004 10:57 PM
checking for duplicates jammykam Access 3 October 2nd, 2003 08:06 PM
Duplicates ashley_y Access 11 August 14th, 2003 03:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.