I am continually amazed by SQL's ability to humble me ....
I have a toy query into a toy database that looks just like this:
SELECT [f].[f]
FROM f, fw, w
WHERE f.id = fw.fid and fw.wid = w.id and w.id in (((((select distinct w.id
from w where w.x in ('a', 'b') )))))
GROUP BY [f].[f]
HAVING count(f.id) = (select count(id) from (((((select distinct w.id from w
where w.x in ('a', 'b') ))))));
The query works and I am basically happy with it as it is, except it
contains the redundant string:
((((select distinct w.id from w where w.x in ('a', 'b'))))
duplicated precisely (I have marked it out with a few extra parens for easy
reading).
I need to do this query at runtime and would prefer not to do it twice ...
it just seems sloppy.
How can I eliminate the redundancy, perhaps by performing this query once
and storing the value to use a second time? Or does the optimizer do this
for me?
IOW, how can I do something like X = ((((select distinct w.id from w where
w.x in ('a', 'b')))), and then use X in place of the second evaluation of
this expression?
Thanks much.
Prefer reply to NG as my usual GMAIL account is flakey right now.
Thank you
RDeW