CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004
    Posts
    187

    Angry MYSQL - Multiple count in rows instead of columns

    When I execute the sql query bellow:

    SELECT (SELECT count(STATE) FROM `table` WHERE STATE='MI') as E1, (SELECT count(STATE) FROM `table` WHERE STATE='ID') as E2 FROM `table`

    the result is something like this:
    E1 E2
    12 15
    One next to the other.

    How could I have the results one BELLOW the other ?!!
    This is what I would like:
    E1 12
    E2 15

    Any ideas?

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: MYSQL - Multiple count in rows instead of columns

    You are actually looking for Group By. A group By would give you result like this

    State Count
    MI 12
    ID 15

    Try this query
    PHP Code:
    Select STATECount(STATEFrom  TABLE Group By STATE 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured