Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> REPOST: Re: Subselect in the from clause
John Russell <netnews2_at_johnrussell.mailshell.com> wrote in message news:<cmc25u49ftq51olke46kic8vqjv9af26l2_at_4ax.com>...
>
> Sometimes you might make the subselect return only a single value,
> just so you can get the same value available in every row of the
> result set:
>
> for item in
> (
> select col1, col2, col3, (select max(col1 + col2) from table) col4
> from table
> )
> loop
> -- item.col4 is the same value on every loop iteration
> -- Getting it via subselect saves declaring a separate variable and
> -- doing a SELECT INTO query.
> ...
>
> John
You, of course, actually meant
select t1.col1, t1.col2, t1.col3, t2.col4 from table t1, (select max(col1+col2) col4 from table) t2
since a subselect cannot be placed in the column list as you illustrated:
SQL> select col1, col2, col3, (select max(col1 + col2) from table) col4 2> from table 3> / select col1, col2, col3, (select max(col1 + col2) from table) col4 *ERROR at line 1:
This message was cancelled from within The Unacanceller's glorious new software, Lotus 1-2-3 For Rogue Cancellers. Received on Fri Jan 25 2002 - 08:59:23 CST