Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 866911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:53:17+00:00 2026-05-15T09:53:17+00:00

I am trying to produce a results table with the last completed course date

  • 0

I am trying to produce a results table with the last completed course date for each course code, as well as the last completed course code overall for each employee. Below is my query:

SELECT employee_number,
       MAX(course_completion_date) 
           OVER (PARTITION BY course_code) AS max_course_date,
       MAX(course_completion_date) AS max_date
FROM employee_course_completion
WHERE course_code IN ('M910303', 'M91301R', 'M91301P')
GROUP BY employee_number

This query produces the following error:

3504 : Selected non-aggregate values must be part of the associated group

If I remove the MAX() OVER (PARTITION BY…) line, the query executes just fine, so I’ve isolated the problem to that line, but after searching these forums and the internet I can’t see what I’m doing wrong. Can anyone help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:53:18+00:00Added an answer on May 15, 2026 at 9:53 am

    As Ponies says in a comment, you cannot mix OLAP functions with aggregate functions.

    Perhaps it’s easier to get the last completion date for each employee, and join that to a dataset containing the last completion date for each of the three targeted courses.

    This is an untested idea that should hopefully put you down the right path:

      SELECT employee_number,
             course_code,
             MAX(course_completion_date) AS max_date,
             lcc.LAST_COURSE_COMPLETED
        FROM employee_course_completion ecc
             LEFT JOIN (
                 SELECT employee_number,
                        MAX(course_completion_date) AS LAST_COURSE_COMPLETED
                   FROM employee_course_completion
                  WHERE course_code IN ('M910303', 'M91301R', 'M91301P')
             ) lcc
             ON lcc.employee_number = ecc.employee_number
       WHERE course_code IN ('M910303', 'M91301R', 'M91301P')
    GROUP BY employee_number, course_code, lcc.LAST_COURSE_COMPLETED
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to produce a report that shows, for each Part No, the results
Im trying to produce a paged table of results which is contained in a
I'm trying to produce the following results: emp_no, book_no, book_id Where emp_no and book_id
Just trying to optimize a SQL Query. SELECT Code, COUNT(*) FROM tblData WHERE ListID
I am trying to do rather complex SQL query to produce a report. This
In trying to produce a list of dict s from a SQLite3 query in
I'm trying to write sql that produces the desired result from the data below.
I am trying to produce a drawing of a 3D sphere within a canvas
I am trying to produce a report which identifies client cases which were open
I'm trying to produce yet another lightbox as much needed HTML/CSS/Javascript practice, but I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.