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 3751974
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:09:00+00:00 2026-05-19T09:09:00+00:00

Okay, another SQL question. What I am trying to achieve is to show by

  • 0

Okay, another SQL question. What I am trying to achieve is to show by company, which courses their employees have been to, and from there, which is the most popular for each company.
Currently, this is what I have:

SELECT a.corporatename, e.course_title, b.studentID
FROM corporate a
JOIN students b ON a.corporateID = b.corporateID
JOIN studentcoursedetails c ON b.studentID = c.studentID
JOIN classdetails d ON c.classdetailID = d.classdetailID
JOIN course e ON d.courseID = e.courseID
WHERE b.corporateID != ‘0’
ORDER BY a.corporatename, e.course_title

This gives me something along these lines:

corporatename—————————–course_title———————————studentID
Deutsche Lufthansa AG Berlin—–Airline Security Operations———5
Deutsche Lufthansa AG Berlin—–Airline Security Operations———6
Deutsche Lufthansa AG Berlin—–Airline Security Operations———5
Deutsche Lufthansa AG Berlin—–Workshop on Crisis Management——6
Deutsche Lufthansa AG Berlin—–Workshop on Crisis Management——7
Korean Air Lines Co., Ltd———-Airline Security Operations———8

From the above, we can see that Lufthansa has sent it’s employees to 2 courses so far. Even though studentID 5 has been to a particular course twice, because he flunked the first try, it is recorded as 2 entries.

What I hope to attain is this:

Deutsche Lufthansa AG Berlin—–Airline Security Operations———3
Deutsche Lufthansa AG Berlin—–Workshop on Crisis Management——2
Korean Air Lines Co., Ltd———-Airline Security Operations———1

I tried to use this code:

SELECT a.corporatename, e.course_title, count( DISTINCT b.studentID ) AS total
FROM corporate a
JOIN students b ON a.corporateID = b.corporateID
JOIN studentcoursedetails c ON b.studentID = c.studentID
JOIN classdetails d ON c.classdetailID = d.classdetailID
JOIN course e ON d.courseID = e.courseID
WHERE b.corporateID != ‘0’
GROUP BY a.corporatename
ORDER BY a.corporatename, e.course_title

But what I got:

corporatename—————————–course_title———————————total
Deutsche Lufthansa AG Berlin—–Workshop on Crisis Management——3
Korean Air Lines Co., Ltd———-Airline Security Operations———1

it shows me the most popular, yes, but I’d like to be able to compare all ranks.
I’d appreciate any help on this.

Thanks to bluish, a simple solution.

SELECT a.corporatename, e.course_title, count( b.studentID ) AS total
FROM corporate a
JOIN students b ON a.corporateID = b.corporateID
JOIN studentcoursedetails c ON b.studentID = c.studentID
JOIN classdetails d ON c.classdetailID = d.classdetailID
JOIN course e ON d.courseID = e.courseID
WHERE b.corporateID != ‘0’
GROUP BY a.corporatename , e.course_title
ORDER BY a.corporatename, e.course_title

I removed the DISTINCT because I need to collect data of all enrollments, not each unique user. Thanks.

  • 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-19T09:09:01+00:00Added an answer on May 19, 2026 at 9:09 am

    Try to add also e.course_title in the GROUP BY:

    SELECT a.corporatename, e.course_title, count( DISTINCT b.studentID ) AS total
    FROM corporate a
    JOIN students b ON a.corporateID = b.corporateID
    JOIN studentcoursedetails c ON b.studentID = c.studentID
    JOIN classdetails d ON c.classdetailID = d.classdetailID
    JOIN course e ON d.courseID = e.courseID
    WHERE b.corporateID != '0'
    GROUP BY a.corporatename, e.course_title
    ORDER BY a.corporatename, e.course_title
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so I have the following Code which appends a string to another in
Okay, so I have another question on a prolog homework problem I am struggling
Okay, I have yet another Code Contracts question. I have a contract on an
Okay so this is another question about a previous question I asked: Rookie SQL
Okay, so I have a Flash CS3 (+ AS3) program which is loading another
Okay, so I have this T-SQL statement: SELECT COUNT(DISTINCT RentalNo) as Count FROM RoomRental
Okay maybe i just need another set of eyes on this, but I have
Okay the previous question was answered clearly, but i found out another problem. What
I have been investigating some performance issues with my database (SQL Server 2008). SQL
Simple question: in MVC, is it okay for one model to interact with another?

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.