On Sat, Jul 5, 2014 at 8:12 AM, Edson Richter edsonrich...@hotmail.com wrote:
Thanks!
I'll investigate (explain) performance for both versions.
also be advised that in most cases when you use SQL 'UNION' you really
should be using 'UNION ALL'. It's a very common mistake:
UNION: form proper
Thanks!I'll investigate (explain) performance for both versions.Atenciosamente,Edson Richter-- Mensagem original --De:David Johnston <david.g.johns...@gmail.com>Data:04/07/2014 21h20Para:Edson Richter;Cc:pgsql-general@postgresql.org;Assunto:Re: Re : [GENERAL] Query top 10 and
with QRY as (select C1.country, C1.state, sum(C1.population)
from places C1
group by 1, 2
order by 3 DESC
limit 10)
select * from QRY
union
select 'others' as country, '' as state, sum(population)
from places
where not exists (select 1 from QRY where country =