Is it possible to get multiple values from a subquery?

后端 未结 7 770
無奈伤痛
無奈伤痛 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:11

    In Oracle query

    select a.x
                ,(select b.y || ',' || b.z
                    from   b
                    where  b.v = a.v
                    and    rownum = 1) as multple_columns
    from   a
    

    can be transformed to:

    select a.x, b1.y, b1.z
    from   a, b b1
    where  b1.rowid = (
           select b.rowid
           from   b
           where  b.v = a.v
           and    rownum = 1
    )
    

    Is useful when we want to prevent duplication for table A. Similarly, we can increase the number of tables:

    .... where (b1.rowid,c1.rowid) = (select b.rowid,c.rowid ....
    

提交回复
热议问题