smti Posted April 13, 2015 Share Posted April 13, 2015 (edited) 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 April 13, 2015 by smti Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 13, 2015 Share Posted April 13, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.