By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,224 Members | 1,037 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,224 IT Pros & Developers. It's quick & easy.

multiple join SQL query

P: n/a
Hi!

I have three tables of hockeystats

players seasons goaliestats
___________ _____________ ______________
|*id |- |*id |- |*id |
|pp | |->|pid | |->|sid |
|firstname | |games | |saves |
|lastname | |goals | |wins |
|___________| |assists | |losses |
|_____________| |______________|

I have this query that doesn't work.

SELECT First(p.firstname), First(p.lastname), Sum(s.games),
Sum(g.saves)
FROM players AS p
INNER JOIN seasons AS s ON p.id = s.pid
LEFT JOIN goaliestats AS g ON s.id = g.sid
WHERE p.pp = 'G'
GROUP BY p.id
ORDER BY Sum(s.games) DESC

data in "seasons" table is mandatory and there are several rows per id
in "players" table. Table goaliestats is kind of extra info for
"seasons" table data and there is one or none rows per id in "seasons"
table.

I would like to get summaries from "seasons" and "goaliestats" grouped
by players.id. If I have to change the table structure I wan't to do
this only for "goaliestats" table. Can anyone help me, please?

thanks,
Yorgos
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
SELECT Sum(s.games), Sum(g.saves), First(p.firstname),
First(p.lastname)
FROM (seasons AS s LEFT JOIN players AS p ON s.pid = p.id)
LEFT JOIN goaliestats AS g ON s.id = g.sid
WHERE p.pp = 'G'
GROUP BY p.id
ORDER BY Sum(s.games) DESC

did the trick!

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.