update A set jp=(select jp from B where no=A.no) where exists (select 1 from B where no=A.no)
楼上的写法是正确的啊,现在有一个问题: update a set jg=(select jg from b where no=a.no) where exists (select 1 from b where no=a.no); 这样写的话没有问题,但是 update a set jg=(select jg from b where no=a.no) where exists (select 1 from a,b where a.no=b.no); 这样写的话还是会把a表中存在而b表中不存在的jg置为null,请问这是为什么啊?
where exists (select 1 from a,b where a.no=b.no); 这个条件永远成立
可是select 1 from b where no=a.no也是永远成立的啊.
SQL> select * from a,b where a.no=b.no;NO JG NO JG ---------- ---------- ---------- ---------- 1 10 1 100SQL> select * from a where exists (select * from b where no=a.no);NO JG ---------- ---------- 1 10 可见两种写法都是返回一行记录的
where exists (select 1 from B where no=A.no)
update a set jg=(select jg from b where no=a.no) where exists (select 1 from b where no=a.no);
这样写的话没有问题,但是
update a set jg=(select jg from b where no=a.no) where exists (select 1 from a,b where a.no=b.no);
这样写的话还是会把a表中存在而b表中不存在的jg置为null,请问这是为什么啊?
这个条件永远成立
---------- ---------- ---------- ----------
1 10 1 100SQL> select * from a where exists (select * from b where no=a.no);NO JG
---------- ----------
1 10
可见两种写法都是返回一行记录的