linq 不包含的查询

[复制链接]
查看11 | 回复3 | 2011-6-1 15:11:33 | 显示全部楼层 |阅读模式
table1
table2
id name class
id name class

1 a
数学
1 a
地理
2 b
英语
2 b
化学
3 c
语文
3 c
语文
4 d
物理
查出table1中name不在table2的name中出现的数据
结果为
4 d
物理

回复

使用道具 举报

千问 | 2011-6-1 15:11:33 | 显示全部楼层
方法很多,一种是集合相交论。另外一种是循环遍历---------------------------------------------------------------------第二种较为容易理解:from p in table1
where !(from z in table2 select z.id).Contains(p.id)select p---------------------------------------------------------------------...
回复

使用道具 举报

千问 | 2011-6-1 15:11:33 | 显示全部楼层
用not in要好点吧select * from table1 a join table2 b on a.id=b.id where a.id not in(select id from table2);...
回复

使用道具 举报

千问 | 2011-6-1 15:11:33 | 显示全部楼层
from a in table1from b in table2where a.nameb.nameselect ........
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行