How to write this query?

Hmongkeysauce

Senior member
Jun 8, 2005
360
0
76
Let's say I have a table name Course. For simplicity, a simplified structure is below:

course_num | name | prereq_course_num

Prereq_course_num is a foreign key referencing Course(course_num).
What would the query look like if I wanted to get the course name, and the name of its pre-req. Note that a course may have only one prereq, but obviously, more than one course may have the same prereq.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Something like "select a.name, b.name from Course a left outer join Course b where a.prereq_course_num = b.course_num"
 

KLin

Lifer
Feb 29, 2000
29,927
366
126
prereq courses should be in a child table IMO to allow you to have multiple prereqs for a single course. Just an observation :).