MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 17th, 2005, 07:09 AM
moogi_75 moogi_75 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 1 moogi_75 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m
Reputation Power: 0
Unhappy Counting Foreign Keys in more than one table

Hi,

I'm hoping someone can help me out with this. It should be a simple thing to do, but I'm no SQL guru and I just can't figure it out...

I want to do a select and include in it the number of matching child records there are in other tables.

Say I have a table of courses and a table also to map users to those courses. Also I have a second table with feedback from the courses, which maps anonymously to the main courses table.

I want to do a SELECT and include columns for the number of people on a course, and the number of feedbacks received (ie. in each of two child tables, count the number of matching foreign keys to the courses primary key).

I've managed to do the first of these like this... (any improvement suggestions welcome!!)

SELECT courses.id, name, org, courses.status, COUNT(courseXuser.courseid) AS num_people FROM courses LEFT JOIN courseXuser ON (courses.id = courseXuser.courseid) GROUP BY courses.id

... but I can't figure out how to also select the number of matching foreign keys in the feedback table too. Just repeating the JOIN and COUNTing doesn't work.

Help!!!

TIA,

Moogi.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Counting Foreign Keys in more than one table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway