在SQL中NOT EXISTS的作用是什么呢?下文就将带您寻找答案,看看SQL中NOT EXISTS究竟如何使用,供您参考。
SQL中NOT EXISTS 的作用与 EXISTS 正相反。假如子查询没有返回行,则满足SQL中NOT EXISTS 中的 WHERE 子句。本示例查找不出版商业书籍的出版商的名称:
USE pubs G OSELECT pub_name FROM publishers WHERE NOT EXISTS (SELECT * FROM titles WHERE pub_id = publishers.pub_id AND type = 'business') ORDER BY pub_name GO
下面是结果集:
pub_name ---------------------------------------- Binnet & Hardley Five Lakes Publishing GGG&G Lucerne Publishing Ramona Publishers Scootney Books (6 row(s) affected)