CoderZone.org

Category: >> mySQL >> Find all duplicates in a column Bookmark and Share

<< lastnext >>

Snippet Name: Find all duplicates in a column

Description: Different ways to find all duplicates in one or more database columns.

Also see:
» Match all #RRGGBB or #RGB values i...
» Active Directory - Reading the Use...
» Print X Column Tables with PHP
» Getting Values Submitted From A Fo...
» Convert Dollars And Cents Value to...
» Toggle a column bit regardless of ...
» Converting Rows to Columns
» Output mySQL data in columns
» TABLE - Multiple Columns
» INDEXES: Single Column Non-unique
» Call subroutine and pass variable ...
» SEQUENCE: Find sequence MAX value
» Search PL/SQL for a string/ key va...
» SEQUENCE: get sequence value into ...
» SELECT: Get DISTINCT / UNIQUE valu...
» SELECT: Get UNIQUE / DISTINCT valu...
» SELECT name columns
» UPDATE: based on multiple returned...
» INSERT: Multiple Column Table Or V...
» INSERT: Multiple Column Table Or V...
» INSERT: Single Column Table Or View
» Show Nth highest value
» List all indexed columns for a giv...
» LAST_VALUE
» FIRST_VALUE
» NVL: Replace NULL values
» CSS Colornames to RGB values
» Select based on a field that can h...
» Reset auto increment value

Comment: (none)

Author: CoderZone
Language: MYSQL
Highlight Mode: MYSQL
Last Modified: December 09th, 2010

-- Depending on your SQL syntax, this might work:
 
SELECT count(*), colname from TABLE 
GROUP by colname HAVING count(*) > 1
 
-- or similarly,
 
SELECT field, COUNT(field) AS itemCount 
FROM table GROUP BY field HAVING ( COUNT(field) > 1 )
 
-- or if trying to find a duplicate combination 
-- of multiple columns try this,
 
SELECT column1, column2, column3, count(column3) 
FROM table GROUP BY column1, column2, column3 
HAVING COUNT(column3) > 1
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 9