Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2009

    Unanswered: Simple Query Help

    Hi. I have a relatively simple question, but it is difficult to describe! Thanks for any help

    I am trying to make a query that accesses multiple tables through the use of foreign keys and JOINs. The trouble I am having is with formatting the output, as such.

    What I need is a count of a combination of two columns.

    E.g. columns:

    Sex FavColour

    M RED
    M BLUE
    M BLUE
    F RED
    F BLUE

    it then looks at each possible Sex and FavColour combination and reports how many instances there are of each:

    M RED 1
    M BLUE 2
    M GREEN 0
    F RED 1
    F BLUE 1
    F GREEN 1

    How can I achieve this?

    Thanks very much

  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    this is exceedingly simple, and it sounds way to much like a homework assignment

    i'll give you two hints: COUNT(*) and GROUP BY

    the rest you will have to come up with yourself | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2009
    That's cool r937.

    I know it is exceedingly simple but hey, beginner, and it's not as if is particularly simple to find things in the manual.

    I was already on the path with GROUP BY in my head, and I will look at the other thing tomorrow. I like working it out for myself anyways.


Posting Permissions

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