首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

这个语句如何写?就这点分了

2012-02-22 
这个语句怎么写?就这点分了有两个表,假设表table1中字段为姓名、单位、住址、电话,表table2中的字段为姓名、单

这个语句怎么写?就这点分了
有两个表,假设表table1中字段为姓名、单位、住址、电话,表table2中的字段为姓名、单位,我怎么用最简单效率最高的方法找到table2中姓名、单位字段内容在table1中姓名、单位字段中不一样的?因为表中记录太多,一般的方法太慢,谢谢

[解决办法]
select * from table2 a where not exists(select * from table1 姓名=a.姓名 and 单位=a.单位)
[解决办法]
select table2.姓名,table2.单位,table1.姓名 from table2 left join table1 on table2.姓名 = table1.姓名 and table2.单位 = table1.单位 where table1.姓名 is null
[解决办法]
select *
from table2 a
where not exists(select 1 from table1 姓名=a.姓名 and 单位=a.单位)
同时在table1(姓名、单位)和table2(姓名、单位)上建立索引

[解决办法]
select * from table2 as tmp
where not exists(select 1 from table1 where 姓名=tmp.姓名 and 单位=tmp.单位)

热点排行