SQL:打印仅发布一本书的发布者的地址

时间:2013-05-03 04:43:21

标签: sql

表格:

auth(auth, age), book(title,auth,pubname), publ(pubname,address)

我试图提出一个查询,打印出版商的地址,这里只发表了一本书,这是我的尝试,请纠正我,如果我错了:这不是作业,它是研究的一部分即将进行的测试指南。

SELECT address 
FROM publ 
WHERE pubname 
  IN ( SELECT pubname 
       FROM book 
       GROUP BY pubname 
         HAVING count(*) = 1)

我认为这是对的,但不确定。

1 个答案:

答案 0 :(得分:0)

按查询分组的内部联接将解决您的问题。

select address from from publ pb 
inner join 
(SELECT pubname 
 FROM   book 
 GROUP BY pubname 
 HAVING count(*) = 1) b
on b.pubname = pb.pubname