2010-06-07 33 views
0

考虑与客户端表和书籍表一个DB:SQL查询的帮助 - 没有关系,找到行

客户:PERSON_ID

书:book_id

Client_Books:为person_id,book_id

你会如何找到所有没有书的Person ID? (没有做外连接和寻找空值)

+2

你为什么反对做一个OUTER JOIN并寻找NULL? – 2010-06-07 14:59:08

回答

2
select * 
from Client 
where person_id not in (select person_id from Client_Books) 
3
select * 
from Client as c 
where not exists(select * from Client_Books where person_id =c.person_id) 
0
SELECT * FROM Client WHERE person_id not in (SELECT person_id FROM Client_Books) 
+0

该死的,只是挨打... – 2010-06-07 14:59:59

0
select * 
from Client as c 
where (select coun(*) from Client_Books where person_id =c.person_id) = 0 

COUNT的完整性,因为有已经存在,并且在解决方案发布。