Thread: sub-selects

sub-selects

From
"Mark Fenbers"
Date:
Is there a way to make a query more efficient by executing a sub-select only once?<br /><br /> In a query such as:<br
/><br/><tt>SELECT a, (select b from c where d = e limit 1), npoints( (select b from c where d = e limit 1) )<br />    
FROMf<br />     WHERE isValid( (select b from c where d = e limit 1) );<br /></tt><br /> I do the same sub-select 3
timesin the query.  I tried the following:<br /><br /><tt>SELECT a, (select b from c where d = e limit 1)<b> AS g</b>,
npoints(<b>g</b> )<br />     FROM f<br />     WHERE isValid( <b>g</b> );<br /></tt><br /> But this gave an error
regarding"column 'g' does not exist".  How can I avoid making the same sub-select 3 times? <br /><br /> Mark<br /> 

Re: sub-selects

From
PFC
Date:
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

?