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

  • Home
  • SEARCH
  • 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 3722366
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:52:41+00:00 2026-05-19T05:52:41+00:00

Right now, I have a query that gets me 3 columns. SELECT a.studentID, a.classdetailID,

  • 0

Right now, I have a query that gets me 3 columns.

SELECT a.studentID, a.classdetailID, c.course_title
FROM studentcoursedetails a, classdetails b, course c
WHERE b.classdetailID = a.classdetailID
AND b.courseID = c.courseID
ORDER BY c.course_title, b.classdetailID

What I get is a column that shows the ID of the student that did the course, the ID of the class they were in and the title of the course itself. Something along these lines:

5---8----Airline Security Operations  
4---8----Airline Security Operations  
6---8----Airline Security Operations  
4---9----Airline Security Operations  
8---10---Airline Security Operations  
5---10---Airline Security Operations  
1---1----Airport Design and Construction  
4---1----Airport Design and Construction  
2---1----Airport Design and Construction  
1---2----Airport Design and Construction

What I need is a table that shows me something like this:

course_title                Number of Classes  Number of students
Airline Security Operations   3                   4

I thought of using CASE, but when I think about it, I just get lost. I’d appreciate your help.

The answer, thanks to gbn:

SELECT c.course_title, COUNT( DISTINCT a.studentID ) AS “Students in Course” , COUNT( DISTINCT a.classdetailID ) AS “Total Classes”
FROM studentcoursedetails a
JOIN classdetails b ON b.classdetailID = a.classdetailID
JOIN course c ON b.courseID = c.courseID
GROUP BY c.course_title

  • 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-19T05:52:42+00:00Added an answer on May 19, 2026 at 5:52 am

    You want to count each distinct occurence per course_title

    Like this (with SQL Server column alias syntax) with proper JOIN syntax

    SELECT
        c.course_title
        ,COUNT(DISTINCT a.studentID) AS [Number of students that have taken the course]
        ,COUNT(DISTINCT a.classdetailID) AS [Number of Classes]
    FROM
        studentcoursedetails a
        JOIN
        classdetails b ON b.classdetailID = a.classdetailID
        JOIN
        course c ON b.courseID = c.courseID
    GROUP BY
        c.course_title
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now, I have a SQL Query like this one: SELECT X, Y FROM
I am in a pickle right now... I have this function that gets 2
Right now I have one query that returns a list of results and displays
I have a select query that is: SELECT id FROM entries WHERE email_address =
Right now I have this SQL query which is valid but always times out:
I'm trying to create a faster query, right now i have large databases. My
Good day! I right now have a function the drags an element from a
Right now I have an SSIS package that runs every morning and gives me
Right now I have a JSP page that allows to sort some items, when
Right now I have a table called Campaigns that has many Hits, if I

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.