How do I find out if there's any duplicate records in a table?

Discussion in 'Databases' started by yangyang, Apr 18, 2008.

  1. #1
    or if there's any 2 or more records with identical value of one of the columns?
     
    yangyang, Apr 18, 2008 IP
  2. LanceT22

    LanceT22 Peon

    Messages:
    653
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    0
    #2
    select col1, col2
    from table
    group by col1, col2
    having count(*) > 1
     
    LanceT22, Apr 18, 2008 IP
  3. yangyang

    yangyang Banned

    Messages:
    757
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks. Got it done by this:

    SELECT name, COUNT(name) FROM authors GROUP BY name HAVING (COUNT(name))

    It's really tricky to handle intricate SQL to do things you previously can't think about.
     
    yangyang, Apr 19, 2008 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    There is no need to use COUNT() twice

    SELECT name, COUNT(*) cnt FROM authors GROUP BY name HAVING cnt>1
    Code (markup):
     
    mwasif, Apr 20, 2008 IP
    ruby90 likes this.