code1: USE pubs SELECT pub_name FROM publishers WHERE EXISTS (SELECT * FROM titles WHERE pub_id = publishers.pub_id AND type = 'business') output: pub_name -------------------- New Moon Books Algodata Infosystems 下列兩種方式均可找出和出版商住在相同城市的作者: USE pubs SELECT au_lname, au_fname FROM authors WHERE city =ANY (SELECT city FROM publishers) -- Or USE pubs SELECT au_lname, au_fname FROM authors WHERE exists (SELECT * FROM publishers WHERE authors.city = publishers.city) 下列為任一種查詢的結果集: au_lname au_fname -------- -------- Carson Cheryl Bennet Abraham (2 row(s) affected) 這兩種查詢均可找出住在以字母 B 開頭之城市的任何出版商所出版的書籍標題: USE pubs SELECT title FROM titles WHERE pub_id IN (SELECT pub_id FROM publishers WHERE city LIKE 'B%') -- Or USE pubs SELECT title FROM titles WHERE EXISTS (SELECT * FROM publishers WHERE pub_id = titles.pub_id AND city LIKE 'B%') 下列為任一種查詢的結果集: title ---------------------------------------------------- The Busy Executive's Database Guide Cooking with Computers: Surreptitious Balance Sheets You Can Combat Computer Stress! Straight Talk About Computers But Is It User Friendly? Secrets of Silicon Valley Net Etiquette Is Anger the Enemy? Life Without Fear Prolonged Data Deprivation: Four Case Studies Emotional Security: A New Algorithm (11 row(s) affected)