Forum Moderators: open
course (id, title, description)
courseoptions (id, courseid, duration, price)
each course can have many courseoptions and linked by course.id = courseoptions.courseid
I would like to display the course.title(s) together in order by lowest courseoptions.price
currently the closest I can attain is
id, title, courseoption.id, duration
4 abc 5 1
10 nat 26 1
11 anot 13 1
4 abc 33 2
10 nat 22 2
SELECT `course`.`id`, `course`.title, `courseoptions`.duration, courseoptions.id FROM `course` , `courseoptions`
WHERE (`courseoptions`.`courseid` = `course`.`id`)
ORDER BY `courseoptions`.`duration`
I am trying to get
id, title, courseoption.id, duration
4 abc 5 1
4 abc 33 2
10 nat 26 1
10 nat 22 2
11 anot 13 1
I would like to display the course.title(s) together in order by lowest courseoptions.price
Probable suggestions would use a combination of group by and order by. However, it may be more logical to group the courses alphabetically and together. If this is the case, this should work:
select course.id, course.title, courseoptions.duration, courseoptions.id from course, courseoptions
where courseoptions.courseid=course.id
order by course.title asc,
courseoptions.duration asc;
Presuming "duration" is what you mean by price. If not, just change "courseoptions.duration" to "courseoptions.price;" the order by field does not have to be selected.
"asc" is not really required as that's the default (I think) but is included for clarity.
[edited by: rocknbil at 4:47 pm (utc) on July 6, 2009]
sadly that doesn't do it, that gives me a result of course.titles in order and courses grouped in order,
duration title
5 Advanced P
5 Advanced R
1 Another
3 Another
4 Another
5 brown
2 Foundation P
1 Foundation Ra
2 Foundation Ra
3 Foundation Ra
4 Foundation Ra
5 Foundation Ra
1 Intermediate P
1 Intermediate P
1 Another
3 Another
4 Another
1 Foundation Ra
2 Foundation Ra
3 Foundation Ra
4 Foundation Ra
5 Foundation Ra
2 Foundation P
5 brown
5 Advanced P
5 Advanced R
course.titles group and ordered by the lowest courseoptions.duration