update 表1 set sname=表2.sname from 表2 where sno=表2.sno
这个送分的?update 表1 set 表1.sname = 表2.sname from 表1,表2 where 表1.sno = 表2.sno
update 表1 set 表1.sname = 表2.sname from 表1,表2 where 表1.sno = 表2.sno 接点分
try:update a set a.sname=b.sname from 表1 a left join 表2 b on a.sno=b.sno
update 表1 set 表1.sname=表2.sname from 表1 on 表2 where 表1.sno=表2.sno
如果是SQL SERVER,不可能不行.create table tb1(sno int,sname varchar(10)) insert into tb1 values(3,null) insert into tb1 values(5,null) insert into tb1 values(7,null) create table tb2(sno int,sname varchar(10)) insert into tb2 values(1,'a') insert into tb2 values(2,'b') insert into tb2 values(3,'c') insert into tb2 values(5,'d') insert into tb2 values(7,'f') goupdate tb1 set tb1.sname = tb2.sname from tb1,tb2 where tb1.sno = tb2.snoselect * from tb1drop table tb1,tb2/* sno sname ----------- ---------- 3 c 5 d 7 f(所影响的行数为 3 行) */
是啊。SQL不肯能通不过的 update a set sname=b.sname from 表1 a,表2 b where a.sno=b.sno
-->测试数据1: @1 declare @1 table (sno tinyint,sname varchar(1)) insert into @1 select 3,null union all select 5,null union all select 7,null -->测试数据2: @2 declare @2 table (sno tinyint,sname varchar(1)) insert into @2 select 1,'a' union all select 2,'b' union all select 3,'c' union all select 5,'d' union all select 7,'f'select * from @1 /* sno sname ---- ----- 3 NULL 5 NULL 7 NULL */update a set a.sname=b.sname from @1 a inner join @2 b on a.sno=b.snoselect * from @1 --> OK /* sno sname ---- ----- 3 c 5 d 7 f */
我的是access数据库啊,上面都试了,说出现语法错误。
试一下这个!update 表1,表2 set 表1.sname=表2.sname where 表1.sno=表2.sno
declare @表1 table (sno int,sname varchar(10)) insert into @表1 select 3,'' insert into @表1 select 5,'' insert into @表1 select 7,'' declare @表2 table (sno int,sname varchar(10)) insert into @表2 select 3,'' insert into @表2 select 3,'' insert into @表2 select 3,'c' insert into @表2 select 5,'d' insert into @表2 select 7,'f'update @表1 set sname=b.sname from @表2 b ,@表1 a where b.sno=a.snoselect * from @表1
set sname=表2.sname
from 表2
where sno=表2.sno
set 表1.sname = 表2.sname
from 表1,表2
where 表1.sno = 表2.sno
set 表1.sname = 表2.sname
from 表1,表2
where 表1.sno = 表2.sno 接点分
set a.sname=b.sname
from 表1 a
left join 表2 b on a.sno=b.sno
set 表1.sname=表2.sname
from 表1 on 表2
where 表1.sno=表2.sno
insert into tb1 values(3,null)
insert into tb1 values(5,null)
insert into tb1 values(7,null)
create table tb2(sno int,sname varchar(10))
insert into tb2 values(1,'a')
insert into tb2 values(2,'b')
insert into tb2 values(3,'c')
insert into tb2 values(5,'d')
insert into tb2 values(7,'f')
goupdate tb1
set tb1.sname = tb2.sname
from tb1,tb2
where tb1.sno = tb2.snoselect * from tb1drop table tb1,tb2/*
sno sname
----------- ----------
3 c
5 d
7 f(所影响的行数为 3 行)
*/
是啊。SQL不肯能通不过的
update a
set sname=b.sname
from 表1 a,表2 b
where a.sno=b.sno
declare @1 table (sno tinyint,sname varchar(1))
insert into @1
select 3,null union all
select 5,null union all
select 7,null
-->测试数据2: @2
declare @2 table (sno tinyint,sname varchar(1))
insert into @2
select 1,'a' union all
select 2,'b' union all
select 3,'c' union all
select 5,'d' union all
select 7,'f'select * from @1
/*
sno sname
---- -----
3 NULL
5 NULL
7 NULL
*/update a set a.sname=b.sname from @1 a inner join @2 b on a.sno=b.snoselect * from @1 --> OK
/*
sno sname
---- -----
3 c
5 d
7 f
*/
set 表1.sname=表2.sname
where 表1.sno=表2.sno
insert into @表1 select 3,''
insert into @表1 select 5,''
insert into @表1 select 7,''
declare @表2 table (sno int,sname varchar(10))
insert into @表2 select 3,''
insert into @表2 select 3,''
insert into @表2 select 3,'c'
insert into @表2 select 5,'d'
insert into @表2 select 7,'f'update @表1 set sname=b.sname from @表2 b ,@表1 a where b.sno=a.snoselect * from @表1