0

So I was reviewing past Exam papers and there was this question I've been trying to solve. It basically requires me to print out text in a certain "template", much like the output I've attempted. Now, this code will mostly work but will break once I try to add the Group function.

SELECT firstname, lecturerID, COUNT(ModuleCode)
from Lecturer
LEFT OUTER JOIN ModuleDelivery 
ON lecturerID = lecturerNo
GROUP BY lecturerID;

edit: I've simplified the code to avoid confusion

any clues as to what might be going wrong?

  • @KenWhite Not a solution, unfortunately :( Ive tried literally everything – Christina .V Jan 06 '22 at 01:01
  • 2
    `GROUP BY` requires that all columns in the `SELECT` that are not aggregated be included. You're missing `firstname`. You need a SQL tutorial. You incorrectly modified the SELECT list after my last comment and left it still invalid. My first comment was correct based on the code you included at that time. – Ken White Jan 06 '22 at 01:02
  • 1
    Does this answer your question? [ORA-00979 not a group by expression](https://stackoverflow.com/questions/1520608/ora-00979-not-a-group-by-expression) – Ken White Jan 06 '22 at 01:04
  • @KenWhite I really do need one. Got any sources as to where I can find a more detailed tutorial on how to properly use the group by function? I would be lying if I said I'm not frustrated by my own cluelessness – Christina .V Jan 06 '22 at 01:05
  • @KenWhite OH MY GOD IT WORKED <3 – Christina .V Jan 06 '22 at 01:06
  • In the future, please do a search of this site for the error message before asking a new question. If you had searched on *ORA-00979: not a GROUP BY expression*, you would have found an answer without needing to write this question at all. – Ken White Jan 06 '22 at 01:08

1 Answers1

1

You need to add firstname to your GROUP BY

GROUP BY firstname, lecturerID

You use an aggregate function (COUNT) on ModuleCode, so any remaining columns must either be aggregate functions (SUM/COUNT/MIN/MAX) or included in group by

(Is this a homework question?)

wrschneider
  • 17,913
  • 16
  • 96
  • 176