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!

Link to comment
https://forums.phpfreaks.com/topic/295513-grouping-data/
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
https://forums.phpfreaks.com/topic/295513-grouping-data/#findComment-1508946
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.