sub-selects

Поиск
Список
Период
Сортировка
Искать

sub-selects

От:
"Mark Fenbers" <Mark.Fenbers@noaa.gov>
Дата:
 Is there a way to make a query more efficient by executing a sub-select only once?

In a query such as:

SELECT a, (select b from c where d = e limit 1), npoints( (select b from c where d = e limit 1) )
    FROM f
    WHERE isValid( (select b from c where d = e limit 1) );

I do the same sub-select 3 times in the query.  I tried the following:

SELECT a, (select b from c where d = e limit 1) AS g, npoints( g )
    FROM f
    WHERE isValid( g );

But this gave an error regarding "column 'g' does not exist".  How can I avoid making the same sub-select 3 times?

Mark

Re: sub-selects

От:
PFC <lists@boutiquenumerique.com>
Дата:

SELECT foo.*,  npoints( foo.g )
FROM
(SELECT a, (select b from c where d = e limit 1) AS g FROM f WHERE  
isValid( g ))
AS foo

?

FAQ