Jump to content

Grouping Data


smti

Recommended Posts

Hello,

 

I have what seems like a basic question, but I'm stumped. Here is my situation; I have a table called courses with the following fields:

 

RID (The Record ID, Pri. Key)

Subject

CID (Course Section)

Section

Name

Instructor

Location

StartTime

EndTime

Days

 

 

What I want to do: I would like to generate a query which provides a list courses taught by each instructor and grouped by the instructor like so:

 

Adams

       - Course A

       - Course B

        - Course C

 

Jones

  -   Course A

   -  Course B

    - Course C

 

 

....And so on......

 

When I tried the following query: Select Instructor, Location, Days, StartTime, EndTime from Courses Group by Instructor; I do get some results, but not all the courses a particular instructor teaches are shown. Is there a better way to make this happen?

 

Thanks for any insight!

Edited by smti
Link to comment
Share on other sites

When you group by, you get one row per group.

 

You could alter the GROUP BY to be either GROUP BY Instructor, RID or Instructor, Name,  however, I typically don't GROUP BY unless there's some group operator I need to apply.

 

In this case, just order the result using ORDER BY Instructor, Name.

 

Note: I'm assuming that "Name" is the course name.

 

Also, all queries return a "result set".  The formatting of those results is something you typically want to handle with a procedural language.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.