Counting Records

Posted on 2005-05-09
Last Modified: 2010-03-19
I don't know if this is possible, but I'm sure one of you guys can figure it out if it is... ;)

I have a table like this

id                    name                   description
-----                -----------              --------------
1111                Mary                    aljkf;lsdjfl;asdjfljdsfjsdj
2222                John                     John Description
3333                John                     John Description
4444                John                     John Description
5555                John                     John Description

The "John" data is old redundant data that serves no significance. I want to go through the data and delete this redundant data if there are 5 or more "John" records.
Is there a way to get back records only if they "repeat" more than, say, 5 times?

Question by:cdfllc
    LVL 28

    Accepted Solution

    Try this:

    SELECT Name
    FROM YourTable
    GROUP BY Name
    HAVING COUNT(*) > 5
    LVL 1

    Author Comment

    Thanks rafrancisco!

    You're my new "DBA" ;)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduced in Microsoft SQL Server 2005, the Copy Database Wizard ( is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
    Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now