Sorry if the title to this post is a bit confusing. My question is rather simple and I know the solution has to do with a join, but I can’t exactly figure out the related posts.
I’m putting together a class schedule in MySQL and the classes have prerequisites. In order to do this, I have 1 table with all of the classes available (ClassName), and, of course, a primary ID (Class_ID). I then have another table of classes offered this semester, built using the information from the “classes available” table. This table starts with a unique id (ClassSemester_ID), Class_ID, and a Prerec_ID for the class’s prerequisite. The Prerec_ID is actually the Class_ID of a different class.
This means that on an actual schedule, I need to the ClassName Column to match up with both Class_ID and Prerec_ID. More visually:
Table 1: AllClasses
Col1: Class_ID
Col2: ClassName
Table 2: SemesterClasses
Col1: ClassSemester_ID
Col2: Class_ID
Col3: Prerec_ID
How do I construct a query that will output both Class_ID and Prerec_ID showing their associated ClassName?
Thanks in advance guys!
-CB
i believe it would be more efficient as
Should return all SemesterClasses rows with the class id, name and pre-requisite name.
One could also add columns in the semesterclasses for the year and such and apply the filters on the where.
Hope it helps