2

I want to have the name in the first colomn but i get an error. When i Let P.name out, the query works but I can't see the player name.

Right now I have the following query:

SELECT P.Name, P.Playernr, SUM (F.Amount)
FROM FINES F
INNER JOIN PLAYERS P
ON F.Playernr = P.Playernr
GROUP BY  P.Playernr

Thanks in advance for help

Onno

3
  • 4
    add the non-aggregated column in the GROUP BY clause. example, GROUP BY P.Name, P.Playernr Commented Nov 12, 2013 at 12:47
  • 1
    Your configuration must have the ONLY_FULL_GROUP_BY option enabled. Commented Nov 12, 2013 at 12:50
  • Just add the P.Name in the Group by, so the aggregate function can work Commented Nov 12, 2013 at 12:55

3 Answers 3

3

You should add it to the GROUP BY clause.

SELECT P.Name, P.Playernr, SUM (F.Amount)
FROM FINES F
INNER JOIN PLAYERS P
ON F.Playernr = P.Playernr
GROUP BY  P.Name,P.Playernr
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

SELECT MAX(P.Name) as Name, P.Playernr, SUM (F.Amount)
FROM FINES F
INNER JOIN PLAYERS P
ON F.Playernr = P.Playernr
GROUP BY  P.Playernr

or add P.Name to the Group BY

SELECT P.Name, P.Playernr, SUM (F.Amount)
FROM FINES F
INNER JOIN PLAYERS P
ON F.Playernr = P.Playernr
GROUP BY  P.Name,P.Playernr

Comments

0

When GROUP BY used, only group by column and aggregation function can be projected. Remove P.Name in projection column or add P.Name in GROUP BY

SELECT P.Name, P.Playernr, SUM (F.Amount)
FROM FINES F
INNER JOIN PLAYERS P
ON F.Playernr = P.Playernr
GROUP BY  P.Playernr, P.Name

In other RDBMS, your query produces error.

think about below data:

P.Playernr   P.Name
A         B
A         C
A         D

then, P.Name is not in GROUP BY, which value is produced in SELECT P.Playernr. so, you must use aggregation function or add P.Name in GROUP BY

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.