SQL - using min and max to retrive rows
im doing a website for a univeristy that holds course information
i have a table - courses - which hold information about courses on offer (not their dates)
now the same course can be run or offered many times during a year
so i have a table - courseoffering - which holds the location the course will be run at, its price etc
now, these courseofferings can run for multiple days or dates (and the university wants to store each day, not just the start day and the end day because each day might start on a different time etc)
so i have a table - courseofferingdates - which will hold a list of days the courseoffering will run for
i need to get a list of all the courseofferings, for a specified course, and the date the courseoffering starts, and the day it ends
so i want:
Code:
SELECT
courseoffering.courseoffering_id,// return all the offerings the course has
min(courseofferingdates.date), // plus the min and max date for each of the offerings
max(courseofferingdates.date)
FROM
courseofferingdates, courseoffering
WHERE
courseoffering.courseoffering_id = courseofferingdates.courseoffering_id
AND
courseoffering.course_id = #mycourse_id# // for the course the user selects