Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: UNION of disjoint SELECTs based on other SELECT - how??
Anneke Treep wrote:
> Hi all,
>
> I am trying to do the following:
> <snip so my amil tool will let me send>
> SELECT (additonal-data)
> FROM additional-tables
> WHERE (person.person-id, session.session-id, 2) IN (
> SELECT (session.id, person.id, session.type)
> FROM (base-tables)
> WHERE (base-restriction)
> ) base_alias
> UNION
> SELECT (other additional-data)
> FROM additional-tables
> WHERE (person.person-id, session.session-id, 3) IN
> base_alias
> ...
> <snip>
> Any suggestions?
> And, is it easy to read the person.id, session.id and session-type along
> with the additional-data?
> Many thanks in advance!
>
> Anneke Treep, Echelon BV
Maybe you don't need to UNION at all. Judging from your pseudo-code you are always selecting from the same tables. So another possibility is to use decode to select the appropriate column from the additional_table based on the session-type.
select decode(session_type, 2, ad.col_1, 3, ad.col_6),
decode(session_type, 2, ad.col_2, 3, ad.col_7), .... repeat for each column ....from base_table, additional_tables ad
HTH
Geoff
Received on Wed Jul 14 1999 - 22:44:29 CDT
![]() |
![]() |