insert into P(aa,bb) select aa,bb from M where aa not in(select aa from N) and bb not in(select bb from N)
用了 "not in" 可能速度会有点慢
“然后删除m和n中同时存在的纪录” 这句怎么写啊,ps:最好还是一句话 比较好~
中海的这个好 select M.aa,M.bb from M left join N on M.aa=N.aa where N.id is null
insert into P(aa,bb) select M.aa,M.bb from M left join N on M.aa=N.aa where N.id is null删除的: 不知道楼主是要删除哪个表的,下面是删除M表中的 delete from M where aa in(select M.aa from M inner join N on M.aa=N.aa and M.bb=N.bb)
insert p (select m.aa,m.bb from m where m.aa+m.bb not in (select n.aa+n.bb from n))
victorycyz(中海)这个 bb怎么没考虑啊,比如 M 表 n表 P表 aa bb aa bb aa bb ------------------------------------------------- 1 4 1 7 1 4 1 6 6 3 1 6 1 7 7 8 11 W 2 3
insert p (select m.aa,m.bb from m where m.aa+m.bb not in (select n.aa+n.bb from n)) 这个有点投机取巧了吧,呵呵,如果 11+34 他等于 1+134么?
insert into P(aa,bb) select aa,bb from M where aa not in(select aa from N) and bb not in(select bb from N) 晕,这个也什么记录也没有哦,
insert into P(aa,bb) select aa,bb from M where aa not in(select aa from N) or bb not in(select bb from N)这个就可以了,不过我去学学 join了,
然后删除m和n中同时存在的纪录
这句怎么写啊,ps:最好还是一句话 比较好~
select M.aa,M.bb
from M left join N on M.aa=N.aa
where N.id is null
不知道楼主是要删除哪个表的,下面是删除M表中的
delete from M where aa in(select M.aa from M inner join N on M.aa=N.aa and M.bb=N.bb)
aa bb aa bb aa bb
-------------------------------------------------
1 4 1 7 1 4
1 6 6 3 1 6
1 7 7 8
11 W
2 3
这个有点投机取巧了吧,呵呵,如果 11+34 他等于 1+134么?
晕,这个也什么记录也没有哦,