求一个算法

smockingandy3 2010-02-08 05:35:35
数据库中两个表,数据量很大,如何筛选出两个表中某列中值不一样的?
如:
表A 表B
col1 col1
a a
b b
b d
c c

我用了两个foreach
foreach(datarow dra in 表A.Rows)
{
foreach(datarow drb in 表B.Rows)
{
if(dra["col1"].tostring()!=drb[col2].tostring())
{
把他提出来
}
}
}
问题是数据量太大了,在asp.net中运行的时间太久了,自动中断了。
不知道该怎么编了,比较笨。谢谢。
...全文
143 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qqiuzaihui 2010-02-08
  • 打赏
  • 举报
回复
引用 1 楼 wxg22526451 的回复:
SQL。先合并再减去交集
SQL codeselect col1from
(select col1from Aunionselect col2from B
) twhere col1notin
(select col1from Aintersect--交集select col1from B
)

UP
wxg22526451 2010-02-08
  • 打赏
  • 举报
回复
如果求某表不在另一张表的,用not in 或not exists就行
select * from @ta a where not exists (select 1 from @tb where col1=a.col1)

用SQL有索引的会快点
wxg22526451 2010-02-08
  • 打赏
  • 举报
回复
SQL。先合并再减去交集
select col1 from
(
select col1 from A
union
select col2 from B
) t
where col1 not in
(
select col1 from A
intersect--交集
select col1 from B
)

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧