Say you have a table layout like the following:
couses:
id (INT), courseName (VARCHAR)
instructors:
id (INT), courseId(INT), instructor(VARCHAR)
Create a query which will print the all the courses and if one instructor is present display their name, if two instructors are present print both of their names on the row in sorted order, if more than two instructors are present instead of the instructors names display “committee“.
For instance your output would look something like this
courseId instructor1 instructor2 0 Edward Yourdon 1 Edward Dijkstra Nicholas Wirth 2 Comittee
Note: Taken from a questionnaire on TheDailyWtf. Not a homework question.
In SQL Anywhere, here’s how you could do it:
Note that this selects ‘profs’ as the list of professors (as stated in the question) as a single column.
I’m not familiar enough with MySQL to know if there is an equivalent to the
list()function.