设为首页 加入收藏

TOP

sql 求两表交集两种方法
2011-06-12 21:44:26 来源: 作者: 【 】 浏览:88次 评论:0

sql 求两表交集两种方法

dept表

id deptid
1 20
2 20
3 20

user表

id userid
1 33
2 34
3 34

方法一

select distinct userid
from user u
where id in (select id from dept where deptid=20)
and not exists (select 1 from user where id in (select id from dept deptid=20) and userid<>u.userid)

方法二 join

select distinct userid
from user u inner join dept d on u.id=d.id
where d.deptid=20
and not exists (select 1 from user inner join dept on user.id=dept.id where userid<>u.userid)

您看到此篇文章时的感受是:
Tags: 责任编辑:administrator
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到QQ空间
分享到: 
上一篇mysql数据库密码忘找回办法 下一篇sql union 效率与union all区别

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

相关栏目

最新文章

图片主题

热门文章

推荐文章

相关文章

广告位