How do I find the Max # of rows ?

  • how do I find the max # of rows within a table based on 2 fields?

    I want to return the max (count) of rows where column A & column B are the same value.

  • Select columna , count(columna) as Counted

    From sometable

    Where columna=columnb

    group by columna

    order by counted desc

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • sorry, I did not explain it very well

    ..... lets say column a has value 20 and columnb has value 30 many time within a table(but I don't know how many times they are repeated ...I want to know the max count for the combination of both fields where columna & columnb. = 20,30 ?

  • so you want a sum of columna and columnb?

    Could you provide sample data and expected results? From there we can create a query.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Try this out....

    select columna, columnb, count(*) from Table

    group by columna, columnb

  • kevin4u06 (12/15/2010)


    Try this out....

    select columna, columnb, count(*) from Table

    group by columna, columnb

  • Thanks.....this works great...I just need to do a join to another table to filter the rows I really wanted.

    Thanks again... you rock!

  • Thanks..... I got it from the reply below and adding a join to filter what I really wanted.

    Thanks again!

Viewing 8 posts - 1 through 7 (of 7 total)

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