t-sql to count how many times a column's value is in a table

Latest post 05-01-2009 1:23 PM by Pat. 0 replies.
  • 05-01-2009 1:23 PM

    • Pat
    • Top 10 Contributor
      Male
    • Joined on 04-27-2008
    • Tempe, AZ
    • Posts 45

    t-sql to count how many times a column's value is in a table

    t-sql to count how many times a column's value is in a table

    SELECT distinct(a.Col1),
    (Select count(Col1) FROM [Table] b where a.Col1= b.Col1) as colcount
    FROM [Table] a
    group by a.Col1 having (Select count(Col1) FROM [Table] b where a.Col1 = b.Col1 ) > 1
    order by colcount desc

    Patrick McNamara, BS-IS/CS, MBA, MAED
    ASP.NET Web Application Developer
    Asteryx, LLC.
    http://asteryx.com
    pat@asteryx.com

    Filed under: ,
Page 1 of 1 (1 items) | RSS
Forums to discuss Microsoft ASP.Net Development and SQL
Powered by Community Server (Non-Commercial Edition), by Telligent Systems