检查一个表的列中的所有值是否都存在于另一个表中

use*_*427 3 sql database oracle

我想知道的命令检查是否都在同一个表(使用select语句创建)的值是出现在其他表都在一个选择statement.for如(使用SELECT命令创建的),我有一个属性fid,并faculty_name教师表并且fid,class_name,room_n○在另一个.我如何检查在所有教室里教授的所有教师?

Nic*_*rey 5

质疑问题,但是

--
-- all faculty without a class
--
select *
from faculty f
where not exists ( select *
                   from class c
                   where c.fid = f.fid
                 )
--
-- all classes wihout faculty
--
select *
from class c
where not exists ( select *
                   from faculty f
                   where f.fid = c.fid
                 )
--
-- all-in-one. Each returned row represents
-- either a faculty or class without a match
-- in the other
--
select *
from      faculty f
full join class   c on c.fid = f.fid
where c.fid is null
   or f.fid is null
Run Code Online (Sandbox Code Playgroud)