要求: 查询条件是id号(int型)在(int数组型)中,int数组也是查询得来的

解决方案 »

  1.   

    也就是说where语句的写法问题 如:id(int类型) in(select aa(int数组类型) from b)
    ,当然这种写法不对,正确的写法是什么
      

  2.   

    --使用 any语法,如下:select * from a where id = any (array(select id from b));
      

  3.   

    --测试如下:--创建表a:int类型
    create table a(id int);
    insert into a values(1);
    insert into a values(2);
    insert into a values(3);
    insert into a values(4);--创建表b:数组int类型
    create table b(id int[]);
    insert into b values('{1,2}');--查询
    select * from a where exists(select 1 from b where a.id = any (b.id));--结果
     id 
    ----
      1
      2
      

  4.   

    可以直接将select的集合变成数组,以前还没有用过
    不过你这句和in没有什么区别select a.id from a where a.id in (select id from b);
    这样写有问题?
    最好不要用in
    用exist
    select a.id from a where exist (select id from b where b.id = a.id)