New to programming: Why can I not alias an inline view in Oracle SQL?

681 Views Asked by At

I am new to programming and I am teaching myself ORACLE sql with a textbook from home. I was wondering if anyone could provide me with an explanation for why this script doesn't work. I have been able to do it alternate ways and get the answer but I just want to understand the fundamentals of why I am not able to alias an inline view. Thanks.

SELECT * FROM  
(  
(SELECT * FROM SECTION WHERE INSTRUCTOR='HERMANO') s  
JOIN Grade_report g  
ON s.section_ID=g.section_id
) v
JOIN Student Stu   
ON stu.stno=v.student_number

Returns:"SQL command not properly ended"

Table Grade_report has columns: section_number, section_ID, Grades;
Table Student has columns: stno (student number);
Table Section has columns: section_ID, Instructor;

1

There are 1 best solutions below

0
On

It doesn't work, because the part that you are trying to give the alias v isn't a valid query:

(
  (SELECT *
  FROM SECTION
  WHERE INSTRUCTOR='HERMANO') s

  JOIN Grade_report g
    ON s.section_ID=g.section_id
) v

You could make it valid by adding an extra select inside that snippet:

SELECT *
FROM
( SELECT * /* This is new */
  FROM
    (SELECT *
    FROM SECTION
    WHERE INSTRUCTOR='HERMANO') s
  JOIN Grade_report g
    ON s.section_ID=g.section_id
) v
JOIN Student Stu
  ON stu.stno=v.student_number

Or you can just remove that alias altogether and have two joins on the same level:

SELECT *
FROM
  (SELECT *
  FROM SECTION
  WHERE INSTRUCTOR='HERMANO') s
  JOIN Grade_report g
    ON s.section_ID=g.section_id
  JOIN Student Stu
    ON stu.stno=v.student_number

Which is essentially the same as:

SELECT *
FROM SECTION s
JOIN Grade_report g
  ON s.section_ID=g.section_id
JOIN Student Stu
  ON stu.stno=v.student_number
WHERE s.INSTRUCTOR='HERMANO'