请教各位以下语句怎么不对?
select * from A where A.code like (select code from B where pcode='111')||'%'要是修改应该怎么修改呢?

解决方案 »

  1.   

    select * from A where A.code like (select code from B where pcode='111')||'%
    红字部分查询的code结果不止一个吧
      

  2.   

    select *
      from A
     where A.code in (select code from B where pcode = '111') 
      

  3.   

    原因是子查询的返回结果是多个。select * from A where A.code IN (select code from B where pcode LIKE '111%';
      

  4.   

    select code from B where pcode='111'这个的查询结果只有一个。这个sql的功能是找到A中以括号内查询结果为前缀的所有结果
      

  5.   

    Quote=引用 4 楼 shiyoumaomao 的回复:]
    select code from B where pcode='111'这个的查询结果只有一个。
    [/Quote]
    那code的查询结果肯定是重复的
    select * from A where A.code like (select distinct  code from B where pcode='111')||'%'
      

  6.   

    code的结果也是唯一的,由pcode可以唯一的得到code,由code也可以获得唯一的pcode可是sql在DB2中就是没法运行啊把语句改成select * from A where A.code =(select distinct code from B where pcode='111')一点问题没有但是我想查询的是:找到A中以括号内查询结果为前缀的所有结果各位高手有没有什么好的解决办法?
      

  7.   

    select A.* from A ,B where instr(A.code,B.code)=1;
    A,B做笛卡尔乘积,然后在A表的code字段找B表的code字段,instr(A.code,B.code)=1,返回从左第一位找到的行(前缀)。