+ -
当前位置:首页 → 问答吧 → sql 查询相同字段表 少掉的数据

sql 查询相同字段表 少掉的数据

时间:2011-12-14

来源:互联网

table1
id name gender age createdate
1 张三 男 23 2011-12-01
2 张三 男 25 2011-12-09
3 李四 女 19 2011-11-03
4 王五 男 28 2011-11-11

table2
id name gender age createdate
1 张三 男 23 2011-12-01
2 李四 女 19 2011-11-03
3 王五 男 28 2011-11-11


1.查询两张表中缺少的数据
2.如果两张表只能据姓名做必配又如何做?

显示结果
id name gender age createdate
2 张三 男 25 2011-12-09
 

作者: CCXY_CPP   发布时间: 2011-12-14

SQL code
select * from table1 
where not exists(select 1 from table2 where name=a.name and gender=a.gender and age=a.age and createdate=a.createdate)

作者: qianjin036a   发布时间: 2011-12-14

select name1字段 from table1 where Name字段 not in (select Name2字段 from Table2表)
1.你看你以哪个表做基准来对比。
2.这二张表不建议你用姓名来做为对比的字段,重名的人太多了。
比如:
1 张三 男 23 2011-12-01
2 张三 男 25 2011-12-09

作者: xfxyxy   发布时间: 2011-12-14

SQL code
select
 * 
from
 table1 a
where
 not exists(select 1 from table2 where name=a.name and gender=a.gender and age=a.age and createdate=a.createdate)


晴天大大写掉了个a

作者: fredrickhu   发布时间: 2011-12-14

热门下载

更多