日期:2014-05-18 浏览次数:20497 次
比较使用 EXISTS 和 IN 的查询 本示例所示查询查找由位于以字母 B 开头的城市中的任一出版商出版的书名: USE pubs GO SELECT title FROM titles WHERE EXISTS (SELECT * FROM publishers WHERE pub_id = titles.pub_id AND city LIKE \'B%\') GO -- Or, using IN: USE pubs GO SELECT title FROM titles WHERE pub_id IN (SELECT pub_id FROM publishers WHERE city LIKE \'B%\') GO E. 使用 NOT EXISTS NOT EXISTS 的作用与 EXISTS 正相反。如果子查询没有返回行,则满足 NOT EXISTS 中的 WHERE 子句。本示例查找不出版商业书籍的出版商的名称: USE pubs GO SELECT pub_name FROM publishers WHERE NOT EXISTS (SELECT * FROM titles WHERE pub_id = publishers.pub_id AND type = \'business\') ORDER BY pub_name GO
------解决方案--------------------
select DISTINCT MD001 from BOMMD WHERE NOT EXISTS (SELECT MC001 FROM BOMMC where BOMMC.MC001 = BOMMD.MD001)