读书人

怎么查询一表排除另一表存在的值

发布时间: 2012-08-10 12:19:33 作者: rapoo

如何查询一表排除另一表存在的值

SQL code
表aid      name    value5695    白老    253286    隐士    265814    别处    255813    rain    115823    rose    7表bpid      name 5695     白老3286     隐士

想要取得表A中value大于10,且这个id是不存在于表b中的。这个sql命令如何写(a.id同b.pid),我要的结果如下
5814别处25
5813rain 11

[解决办法]
探讨

SQL code
select
*
from a
where not exists(select 1 from b where pid=a.id) and a.value>10

[解决办法]
SQL code
select * from tawhere not exists(select 1 from tb where pid=ta.id)       and ta.value>10 

读书人网 >SQL Server

热点推荐