--测试: create table tb1(id char(2),name varchar2(6)); insert into tb1 values('01','张一'); insert into tb1 values('02','李二');create table tb2(id char(2),name varchar2(6)); insert into tb2 values('01','张三'); insert into tb2 values('01','张四'); insert into tb2 values('02','李五'); insert into tb2 values('02','李六'); insert into tb2 values('02','李七');update tb1 set name = (select name from tb2 where id = tb1.id and rownum = 1); select * from tb1; /*结果 ID NAME -- ------ 01 张三 02 李五 */drop table tb1; drop table tb2;
提示信息:
ORA-01427:Single-row subquery returns more than one row
update table1 set name = (select name from table2 where date = table1.date and rownum = 1)
你的那条sql语句执行之后,table1表中name字段的值全部都是table2表中第一条记录name字段的值.
而我要求的是,table1表中的name的值要和table2表中的name值一一对应。to:hero1981(英雄)
你的那条sql语句执行之后,table1表中name字段的值全部都是table2表中name字段的最大值.看看是否有正确解决的办法,谢谢各位了!
and name = table1.name and rownum = 1)
看看是否有正确解决的办法,谢谢各位了!
create table tb1(id char(2),name varchar2(6));
insert into tb1 values('01','张一');
insert into tb1 values('02','李二');create table tb2(id char(2),name varchar2(6));
insert into tb2 values('01','张三');
insert into tb2 values('01','张四');
insert into tb2 values('02','李五');
insert into tb2 values('02','李六');
insert into tb2 values('02','李七');update tb1 set name = (select name from tb2 where id = tb1.id and rownum = 1);
select * from tb1;
/*结果
ID NAME
-- ------
01 张三
02 李五
*/drop table tb1;
drop table tb2;
你的方法没有问题,可能是我前面做的时候,数据库的数据有点问题,没有做出正确的结果,现在好了!