• Eirikur Eiriksson (11/18/2014)


    serg-52 (11/18/2014)


    kriskumark96 (11/17/2014)


    Hi,

    The three queries is of the same tables with different where condition are used , so that we cannot have a join or cross join on it

    Or

    Is there any way to add 2 different queries as a single resultant

    select col1 from tb1 where col2=''

    select col4 from tb1 where col3=''

    the resultant should be col1,col4

    Just a guess, if the first select returns

    A

    B

    C

    , and the second one returns

    1

    2

    do you need

    A 1

    B 2

    C NULL

    ?

    Then number the results as you need and full-join them by those numberings.

    select t1.col1, t2.col4

    from (select row_number() over (order by ...) as n, col1

    from tb1 where col2='') as t1

    full outer join (select row_number() over (order by ...) as n, col4

    from tb1 where col3='') as t2 on t1.n=t2.n

    you need to choose how the results should be ordered.

    Quick thought, this will indeed produce a set which has the desired columns but those values will be paired/matched by the over/order clause in the individual queries, hence the cardinality and the value distribution will control the "implied" relationship. If the over/order clause columns are the same in all query instances, those columns are then effectively the common key for the set and can therefore be used as such!

    😎

    If data is inserted into the table then that sort order may get mangled and may not serve as the keys anymore. It is better to establish a definitive key relationship between the two sets.

    ----------------------------------------------------