mysql中 下边这句话怎么改能成功呢 
update category set country=(
            select xx.country from ( 
                     select * from category where  parentid=left(parentid,8)  and     country=''
    )xx
);
[Err] 1242 - Subquery returns more than 1 row
我知道啥意思 就不会修改
这是在一个表内的相同字段关联,因为有的country不是空的 我要把为空的country通过parentid关联起来 然后把country更新。

解决方案 »

  1.   

    update category set country=(
                select xx.country from ( 
                         select * from category where  parentid=left(parentid,8)  and     country=''
        )xx
    );
    update category A,category  B
    set A.country=B.country
    where  B.parentid=left(A.parentid,8) and B.country='' 
      

  2.   

    我要是用 like匹配该怎么写呢? where  B.parentid like %left(A.parentid,8)%????? 
      

  3.   

    ---like性能比较低的。
    update category A,category  B
    set A.country=B.country
    where  B.parentid=left(A.parentid,8) and B.country='';
      

  4.   

    因为parentid a的是原来的长度有的是16位有的是8为 b里面都是8位的 要匹配的话 只能用like
      

  5.   

    update category set country in (
                select xx.country from ( 
                         select * from category where  parentid=left(parentid,8)  and     country=''
        )xx
    );
      

  6.   

    update category set country=(
                select min(xx.country) from ( 
                         select * from category where  parentid=left(parentid,8)  and     country=''
        )xx
    );
      

  7.   

    贴建表及插入记录的SQL,及要求结果出来看看
    update category a ,
    (select * from category where  parentid=left(parentid,8) and country='') b
    set a.country=b.country