On Wed, Jan 28, 2009 at 11:47 AM, dariuszs <dariuszs@svnp.com> wrote:
Hi,
If I rewrite this query like this

select * from (select gender,count(*) from table1 group by gender) as t1
where t1.gender in ('F','M');

It takes about 2 seconds which is wonderful however how do I apply this
to very complicated queries? Thanks. Dariusz.

I might suggest that it will be cleaner to do it this way.

select gender, count(*)
from table1
group by gender
having gender in ('F','M');

(In the past, I've found that the construct "select ... from (select ....)" ends up creating SQL that's really hard to debug.  YMMV.)