select STUDENTS.name, INSTRUCTORS.name
from students full outer join advising
using(stno)
full outer join instructors
using(empno);
This will result in
sname iname
-----------------------------------------------------
Grogan A. Mary Evans Robert
Edwards P. David Evans Robert
Rawlings Jerry Exxon George
McLane Sandy Exxon George
Mixon Leatha Exxon George
Novak Roland Sawyer Kathy
Pierce Richard Davis William
Lewis Jerry Will Samuel
Prior Lorraine Will Samuel
Chu Martin
Davis Richard
Campbell Kenneth
5.10 Sets and subqueries
Subqueries are select phrases that return sets rather than tables. Their main
use is in conditions that involve sets. As we shall see, they are useful in imple-
menting difference and division
in SQL. Syntactically, a subquery is written by placing a select phrase
between a pair of parentheses. For example,
(select empno from INSTRUCTORS where rank = ’Professor’);
5.10 Sets and subqueries 95
is a subquery that computes the employee numbers of full professors. To find
the student numbers of students who take a course with a full professor, we
need to select those GRADES tuples whose empno belongs to this set. This can
be accomplished by writing:
select distinct stno from GRADES where
empno in (select empno from INSTRUCTORS
where rank = ’Professor’);
This will return the result: