SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: How to find duplicate entry ?

  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to find duplicate entry ?

    I have a table where cityName is a column.

    I want to find if there are same cityName exists and if so how many count for each entry.

    What is the query ?

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Location
    OH, USA
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that will give you all duplicates and number of them

    select count(cityName) as num, cityName
    from yourTable
    having count(cityName)>1
    group by cityName

  3. #3
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,462
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by gk53 View Post
    that will give you all duplicates and number of them
    very close...

    ... but HAVING comes after GROUP BY

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •