sql query

  • I have a table wit this data

    name number

    a 1

    b 2

    c 3

    a 4

    a 5

    b 6

    a 7

    d 8

    d 9

    I wrote a query select name,count(*) from tableA group by name

    Then i got the result

    name count

    a 4

    b 2

    d 2

    c 1

    what i need from u people is that i want names which has count=2

    how to extend the first query to get this result.

    Thanks in advance

  • select name,count(*)

    from tableA

    group by name

    having count(*) = 2

  • thanks for the answer and I need some more help.I wanted to know howmany of them has count=2.

    Thanks in advance.

  • OK, for that you can use a sub-query, like this:

    select count(*)

    from (select name, c = count(*)

    from tableA

    group by name) Tbl

    where c = 2

  • Thanks.it works fine

Viewing 5 posts - 1 through 4 (of 4 total)

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