日期:2014-05-18  浏览次数:20387 次

两数据库链接查询
数据库a

user_id     user     biaoji
    1             aaa         1
    2             bbb         0
    3             ccc         1

数据库b

info_id     info     flag     userid
    1             a11         1             1
    2             a22         0             1
    3             a33         0             1
    4             b11         1             2
    5             b22         0             2
    6             c11         0             3
    7             c22         0             3
    8             c22         0             3

a.user_id   关联   b.userid

查询数据表a中标记(biaoji=1)的用户,在数据表b中用户的全部标记(flag=0)。

怎么能把用户ccc查询出来。各位高手求救。

------解决方案--------------------
两个数据库在同一台数据库服务器上还是在不同的服务器?
------解决方案--------------------
select t.*
from A as t
where t.biaoji=1 and not exists (select * from b where user_id=t.user_id and flag=1)