counting duplicates from a table

  • HI, can someone help me with this query.

    lets say i have a table with the below values in the someNumber column.

    I want to count the number of duplicates for each value in this column in a result set.

    idNumber (Column)

    123

    456

    789

    000

    123

    123

    I want the result to be:

    idNumber | numberOfInstances

    123 3

    456 1

    000 1

    Can anyone help me out with this?

    Thanks!!

  • Hi I think it would be something like this:

    select idNumber,count(idNumber) from dbo.Empleado

    group by idNumber

    and if you only want the records that appear more than once, then you should probably add a having clause, like this: having count(idNumber)>1

  • that works great, thanks!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply