Както други споменаха, естествените съединения винаги са били лоша идея. Ами ако някой добави description
колона към двете COURSE
и GRADE
? Както и да е, колоните, използвани в естествено съединение, не могат да бъдат квалифицирани с псевдоним на таблица.
create table student
( student_id integer primary key
, student_name varchar2(30) not null );
create table course
( course_id integer primary key
, course_name varchar2(30) not null );
create table grade
( student_id references student not null
, course_id references course not null
, grade varchar2(3) not null );
Заявка:
select student_id, student_name, course_id, course_name, grade
from student
natural left join grade
natural left join course;
Създайте изглед:
create or replace view student_view as
select course_id, student_id, student_name, grade, course_name
from student
natural left outer join grade
natural left outer join course
union all
select course_id, student_id, student_name, grade, course_name
from course
natural left outer join grade
natural left outer join student
where student_id is null;
Продължение по вашия друг въпрос...