是否可以编写一个无需子选择即可执行此操作的 SQL 查询?
想象一个一对多的关系,例如:
Mail: subject, date etc
Recipient: address
是否可以不使用子选择执行此查询:[电子邮件受保护] 没有来自同一域 @domain.com 的其他收件人?
我能找到的唯一方法是使用子选择:
select mail m, recipient r where m.pkm=r.pkm
and (r.address='[email protected]')
and not exists (select * from mail ms, recipient rs where m.pkm=ms.pkm and ms.pkm=rs.pkm and rs.address<>'[email protected]' and rs.address like '%@domain.com')
Imagine a relation one to many, for example:
Mail: subject, date etc
Recipient: address
Is it possible to do this query WITHOUT using a subselect: all mail received by [email protected] that did not have another recipient from the same domain @domain.com??
the only way I can find is using a subselect:
select mail m, recipient r where m.pkm=r.pkm
and (r.address='[email protected]')
and not exists (select * from mail ms, recipient rs where m.pkm=ms.pkm and ms.pkm=rs.pkm and rs.address<>'[email protected]' and rs.address like '%@domain.com')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定这是否比你原来的好! -- 它仍然有一个子选择 -- 但允许域不是文字“domain.com”。
hth,R
I'm not sure this is any better than your original! -- it still has a sub-select -- but allows for domains to be other than the literal 'domain.com'.
hth, R