From: | "Mark Fenbers" <Mark(dot)Fenbers(at)noaa(dot)gov> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | sub-selects |
Date: | 2005-05-16 19:45:43 |
Message-ID: | 4288F867.8090600@noaa.gov |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
Attachment | Content-Type | Size |
---|---|---|
unknown_filename | text/html | 965 bytes |
Mark.Fenbers.vcf | text/x-vcard | 283 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | PFC | 2005-05-16 20:36:01 | Re: sub-selects |
Previous Message | Ragnar Hafstað | 2005-05-16 19:32:40 | Re: ORDER BY handling mixed integer and varchar values |