1. 表A id....
表B id....两表的ID是一样的,查找出A表中不包含B表ID的数据select * from a where id not in (select id from B);
这是我写的,但是他说用Not in效率太低,可否有别的方法,我就答不出来了
2. 表c
logID(流水号) id(有重复的id,但是越往下的是越新的)
1 30
2 30
3 31
4 32
5 32
6 33
查找出所有最新没有重复的id
结果: logId id
2 30
3 31
5 32
求教,谢谢
表B id....两表的ID是一样的,查找出A表中不包含B表ID的数据select * from a where id not in (select id from B);
这是我写的,但是他说用Not in效率太低,可否有别的方法,我就答不出来了
2. 表c
logID(流水号) id(有重复的id,但是越往下的是越新的)
1 30
2 30
3 31
4 32
5 32
6 33
查找出所有最新没有重复的id
结果: logId id
2 30
3 31
5 32
求教,谢谢
select * from a where not exists(select 1 from b where b.id=a.id)
2.
select * from c a where not exists(select 1 from c b where a.id=b.id and a.logid<b.logid)
2.select * from c as a where logID=(select max(logID) from c where id=a.id)
where id=a.id)
1、用except
2、用exists辅助max函数
select max(logID),id from 表c group by id
不对吗??