If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Simple Query Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-16-09, 20:27
dakky316 dakky316 is offline
Registered User
 
Join Date: Nov 2009
Posts: 2
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
F GREEN


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
Reply With Quote
  #2 (permalink)  
Old 11-16-09, 22:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-16-09, 22:58
dakky316 dakky316 is offline
Registered User
 
Join Date: Nov 2009
Posts: 2
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.

Cheers
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On