I Can't select the fields i need in the query result!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mrdatabase1
    New Member
    • Apr 2012
    • 1

    I Can't select the fields i need in the query result!

    I have this query and it works fine however i need the query to display the forename and surname and currently it only displays the max value of the sum it performs

    Does anybody know what i can do?

    Thanks
    Code:
    SELECT MAX(Intermediate.Total_Amount_Of_Likes) AS Total_Amount_Of_Likes
    FROM (
    SELECT Forename, Surname, Sum(Likes) AS Total_Amount_Of_Likes
    FROM Instructors, Exercise_Class_Type, Exercise_Class_Staff, Exercise_Class_Booking, Feedback
    WHERE Exercise_Class_Type.Exercise_Class_ID = Exercise_Class_Staff.Exercise_Class_ID
    AND Exercise_Class_Type.Exercise_Class_ID = Exercise_Class_Booking.Exercise_Class_ID 
    AND Exercise_Class_Booking.Exercise_Booking_ID = Feedback.Exercise_Booking_ID
    AND Instructors.Instructor_ID = Exercise_Class_Staff.Instructor_ID
    AND Start_Date_Time >= Date() - 30
    GROUP BY Forename, Surname
    ) Intermediate;
    Last edited by NeoPa; Apr 29 '12, 12:03 PM. Reason: Added mandatory [CODE] tags for you
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    What you have here is a sub-query running in the background. The only field that will be displayed is the max value as you have discovered. You should be able to get the results that you are looking for by adding the following to the end of line 1 of your code:

    Code:
    , Forename, Surname
    This will pull those fields from the sub-query (the subquery is the part between the ( in line 2 and the ) in line 11)

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      Sorry Seth, but the outer query is also aggregated (IE. as well as the subquery). The OP is after identifying which of the aggregated records of the subquery is reflected by the value returned as the maximum value for [Total_Amount_Of _Likes].

      Comment

      Working...