Search code examples
sqloracleoracle-sqldeveloper

Need to get description of a different column in my SQL query


The table I'm working with has 8 different columns, I'm working with three called course_no, prerequisite, and description. the prerequisite shows what is needed to get into the course_no and the description currently shows the course_no description. I however need to get the description of the prerequisite while still showing the course_no. I am unsure of how to do this. I've looked up inner joins but they don't seem to be what im looking for. This is the sql statement just need to help figuring out how to show the description for the prerequisite column rather than course_no column.

SELECT course_no, prerequisite, description
FROM course

Solution

  • I think join is what you are looking for. Perhaps:

    select c.*, p.description as prerequisite_description
    from course c left join
         course p
         on c.prerequisite = p.course_no;