Is it possible to get multiple values from a subquery?

后端 未结 7 774
無奈伤痛
無奈伤痛 2021-02-06 22:49

Is there any way to have a subquery return multiple columns in oracle db? (I know this specific sql will result in an error, but it sums up what I want pretty well)



        
7条回答
  •  情书的邮戳
    2021-02-06 23:05

    It's incorrect, but you can try this instead:

    select
        a.x,
        ( select b.y from b where b.v = a.v) as by,
        ( select b.z from b where b.v = a.v) as bz
    from a
    

    you can also use subquery in join

     select
            a.x,
            b.y,
            b.z
        from a
        left join (select y,z from b where ... ) b on b.v = a.v
    

    or

       select
            a.x,
            b.y,
            b.z
        from a
        left join b on b.v = a.v
    

提交回复
热议问题