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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:22:02+00:00 2026-05-31T03:22:02+00:00

Good Morning All. I have a table structure (I am using SQL SERVER 2000)

  • 0

Good Morning All.

I have a table structure (I am using SQL SERVER 2000)

CourseID StudentName TermPaperID

101         Jon            1   
101         Jon            2
101         Jon            3
101         David          1   
101         David          2
102         David          5 
102         David          6 
102         George         5  

I would like to list out CourseID,StudentName,Maximum registration per Course.

I tried the following Query

select 
CourseId,
StudentName,
max(x.numberofregistration) as max_registration
from
(
   select 
           CourseID,
           StudentName,
           count(CourseID) as numberofregistration 
    from 
    dbo.Students 
            group by CourseId,StudentName
 )x
 group by CourseId,StudentName

but it did no give the expected result.

The expected result is
I have a table structure

CourseID StudentName max_registration

101         Jon            3   
102         David          2

How to achieve the expected result? Thanks in advance.

  • 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-31T03:22:04+00:00Added an answer on May 31, 2026 at 3:22 am

    Here’s a really, really ugly way. I think I’d rather pony up the upgrade fee than write too many of these. Hopefully someone else will come up with something cleaner.

    CREATE TABLE #x(CourseID INT, StudentName VARCHAR(32), TermPaperID INT);
    
    INSERT #x SELECT 101,'Jon   ',1;   
    INSERT #x SELECT 101,'Jon   ',2;
    INSERT #x SELECT 101,'Jon   ',3;
    INSERT #x SELECT 101,'David ',1;   
    INSERT #x SELECT 101,'David ',2;
    INSERT #x SELECT 102,'David ',5; 
    INSERT #x SELECT 102,'David ',6; 
    INSERT #x SELECT 102,'George',5;
    
    SELECT b.CourseID, b.StudentName, max_registration = COUNT(*)
    FROM #x AS b
    INNER JOIN (
      SELECT CourseID, c = MAX(c)
      FROM
      (
        SELECT CourseID, StudentName, c = COUNT(CourseID) 
        FROM #x GROUP BY CourseID, StudentName
      ) AS x GROUP BY CourseID
    ) AS s
    ON b.CourseID = s.CourseID
    GROUP BY b.CourseID, b.StudentName
    HAVING COUNT(*) = MAX(s.c)
    ORDER BY b.CourseID;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Morning All, I have code similar to the following try{ using(var tx =
Good Morning, I have connected to my SQL Server 2005 - and have managed
Good morning all, I'm sure this is a gimme, but I have no idea
Good Morning All, I have loaded over 1,300 blurbs into my client's database with
Good morning all. I'm having a small crisis with table views in a 3.1
Good Morning All! I have been developing a project for some time in which
Good Morning All, I have a project which will be distributed as an Excel
Good morning all. I have an issue with a query. I want to select
Good morning, I have problem with using MasterPage and jQuery. I using jQuery UI
Good Morning All, I have an Objective C question that is coming from JavaScript.

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.