Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 7FBC99FB1B7 for ; Mon, 16 Jul 2007 08:06:41 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 45472-10 for ; Mon, 16 Jul 2007 08:06:21 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.173]) by postgresql.org (Postfix) with ESMTP id DF18E9FA433 for ; Mon, 16 Jul 2007 08:06:34 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id a2so1065963ugf for ; Mon, 16 Jul 2007 04:06:24 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; b=Jl5SQ2L3cgAVDWeFDr+grSRW+eXQQTqDlJ98Pu6xspD6QSzjkEObI5WDrhehH0gXYxk5pMEUFpHYwxUR5cGlXHArgT0Ivgse+GTzLhUXTJjMKn8/+5FA95do8WdvNJhkp0YwAuWftcr59laHnshTrY6uk73v27PXxna2QxWRuOM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; b=UAl8AcYY/90+cvlNYXRWy3ZgiyorHwiZYVv9tUlzA2QFIGfdFd0q9fJcborepwLDdSM4Hx/FLclozcKesS+ygAoMDTpL6brLdQefGGIw4LRjgxE7D7pPUigjPBatwbSZLHznqgyvcHQOtf63Evnc2+Z3wz+y789tWeri6BVO2ug= Received: by 10.67.119.13 with SMTP id w13mr4229687ugm.1184583984207; Mon, 16 Jul 2007 04:06:24 -0700 (PDT) Received: from ?192.168.10.68? ( [62.57.108.235]) by mx.google.com with ESMTP id z34sm40659077ikz.2007.07.16.04.06.22 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 16 Jul 2007 04:06:23 -0700 (PDT) Message-ID: <469B512D.70507@gmail.com> Date: Mon, 16 Jul 2007 13:06:21 +0200 From: =?ISO-8859-1?Q?Dani_Casta=F1os?= User-Agent: Thunderbird 2.0.0.4 (Windows/20070604) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Having the sum of two queries Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/91 X-Sequence-Number: 28826 Hi all! I want to do something like this: SELECT status, COUNT( status ) AS total FROM users GROUP BY status UNION SELECT status, COUNT(status) AS total FROM imported_users GROUP BY status And have the result of both added. I've tried something like SELECT tot.status, COUNT(total) FROM( QUERY A UNION QUERY B ) AS tot GROUP BY tot.status But it doesn't works. It doesn't add the total columns with the same status...