Skip to main content
Inspiring
January 16, 2008
Question

Another Set of Eyes Please

  • January 16, 2008
  • 2 replies
  • 275 views
Hello - I've looked through this a hundred times and can not figure out
what the issue is. Can I borrow another set of eyes to tell me what I am
missing?

SELECT Members.member_ID, Members.member_FirstName,
Members.member_LastName, Results.results_MemID,
Sum(Results.results_Points) AS Total_Pts
FROM Members INNER JOIN Results ON Members.member_ID = Results.results_MemID
GROUP BY Members.member_ID

This version works:
SELECT results_MemID, Sum(results_Points) AS Total_Pts
FROM Results
GROUP BY results_MemID

But I need to get the Member ID, First and Last Names from the Members
table.

Thank you in advance for any help,
Steve
This topic has been closed for replies.

2 replies

Inspiring
January 16, 2008
Hi Ian - Thank you for the quick response. With your help I was able to
get the results I wanted.

Thanks again,
Steve

Ian Skinner wrote:
> Steve Miller wrote:
> > SELECT Members.member_ID, Members.member_FirstName,
>> Members.member_LastName, Results.results_MemID,
>> Sum(Results.results_Points) AS Total_Pts
>> FROM Members INNER JOIN Results ON Members.member_ID =
>> Results.results_MemID
>> GROUP BY Members.member_ID
>
> When you use a SQL aggregate function, SUM() in your case, all the
> fields in the SELECT clause must either be in an aggregate function OR
> the GROUP BY clause. You need to put member_firstName, member_LastName
> and resutls_MemID into one of these locations.
>
> Doing this may very well provide different results then what you want
> depending exactly on what data you are summing and selecting. Sometimes
> you have to have your analysis queries separate from your basic select
> queries and then join the results up in the output.
>
> Also be aware that what order you put the fields into the GROUP BY
> clause may change the results, again depending on the nature of your data.
>
>> This version works:
>> SELECT results_MemID, Sum(results_Points) AS Total_Pts
>> FROM Results
>> GROUP BY results_MemID
>
> All the fields in the SELECT clause, results_memID and results_points,
> are either in an aggregate function, SUM() or the GROUP BY clause.
>
Inspiring
January 16, 2008
Steve Miller wrote:
> SELECT Members.member_ID, Members.member_FirstName,
> Members.member_LastName, Results.results_MemID,
> Sum(Results.results_Points) AS Total_Pts
> FROM Members INNER JOIN Results ON Members.member_ID =
> Results.results_MemID
> GROUP BY Members.member_ID

When you use a SQL aggregate function, SUM() in your case, all the
fields in the SELECT clause must either be in an aggregate function OR
the GROUP BY clause. You need to put member_firstName, member_LastName
and resutls_MemID into one of these locations.

Doing this may very well provide different results then what you want
depending exactly on what data you are summing and selecting. Sometimes
you have to have your analysis queries separate from your basic select
queries and then join the results up in the output.

Also be aware that what order you put the fields into the GROUP BY
clause may change the results, again depending on the nature of your data.

> This version works:
> SELECT results_MemID, Sum(results_Points) AS Total_Pts
> FROM Results
> GROUP BY results_MemID

All the fields in the SELECT clause, results_memID and results_points,
are either in an aggregate function, SUM() or the GROUP BY clause.