Tom Lane wrote:
> 
> "Eric Jain" <[EMAIL PROTECTED]> writes:
> > Any ideas how the following two statements could be combined into a
> > single one?
> 
> > SELECT DISTINCT host, url, id
> > INTO TEMP
> > FROM log
> > WHERE
> >   host IN (SELECT host FROM robots)
> >   AND status IN (200, 304);
> 
> > SELECT host, COUNT(*) AS hits
> > FROM TEMP
> > GROUP BY host
> > ORDER BY hits DESC;
> 
> Offhand I do not think you can do this in one "simple" SQL query,
> because the SQL query semantics require that GROUP BY grouping occurs
> before DISTINCT processing, whereas you want the other order.
> 
> 
> For now, the temp table seems like a good workaround.
> 

And splitting some complex queries in simpler ones (using temp tables) can
increase performance, depending on the query.

Regards,
Guillaume Perréal - Stagiaire MIAG
Cemagref (URH), Lyon, France
Tél: (+33) 4.72.20.87.64

Reply via email to