Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mTQSh-0007wA-Il for pgsql-general@arkaria.postgresql.org; Thu, 23 Sep 2021 15:16:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mTQSf-00076q-RT for pgsql-general@arkaria.postgresql.org; Thu, 23 Sep 2021 15:16:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mTQSf-00076i-Ib for pgsql-general@lists.postgresql.org; Thu, 23 Sep 2021 15:16:33 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mTQSd-0006NU-CF for pgsql-general@lists.postgresql.org; Thu, 23 Sep 2021 15:16:32 +0000 Received: by mail-wr1-x42a.google.com with SMTP id t28so4826224wra.7 for ; Thu, 23 Sep 2021 08:16:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=reply-to:from:to:cc:references:in-reply-to:subject:date:message-id :mime-version:content-transfer-encoding:thread-index :content-language; bh=fi8dlgvX0V7jfuNIkVsP3tULjQk/8EEzTNdSlxUJFSU=; b=GEJb3Ioo/XGoZVrPc1l4nwdbsQi5lj6zQkTxVTfX2jfBhmbE6J6ar4jt9meMe8ca3Q AFzwoskMFVYLSl+04yoEjyqaFfR5dSbxCfFE5m1tokWaDNUXN7SmbLFqBoDOdhO6zo7q d0SpqNg+YyrrNtaf/ti5z4mekb45P9NucQmaP8uQRtkaPbDTz1qYl0E7tI4R9nBuvvAf A16khbzo6RDZRN23ejAQXyrvzyjXzrPW7svoAVOpxm/Uvml7n9TkVIGFUC3Bzoqzs7mm u3cI3CI2/kDDRwTwpEwugrPC15zqCNCYCwRNFrJyBrGdlmBzbe+jgReMuifaxVhy7sHI pNog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:from:to:cc:references:in-reply-to :subject:date:message-id:mime-version:content-transfer-encoding :thread-index:content-language; bh=fi8dlgvX0V7jfuNIkVsP3tULjQk/8EEzTNdSlxUJFSU=; b=1/+0CmNnP6znDeGcemU+n9ZAtVDxoiC3sdYUYFX7wOPzc7f4eKI7G8AwGg4iORl9Df kSle67jDo7Ob8g8/m5ZEV5HqrIto+35mdcshhpKqqcJ/c6cUTNLiLWsL8yCmvmmWGO1y 9YQ7r3hTaO30KYJjXoTEM7FD6u22KnggT5XtQIyMtUFsZtlQUp3WBzGmLu62pRsA0bdc l8dIFgtnrYhDXK9BakJ3EXTD7bph1iVmIqSticryo5KzHfELnHnBldq3+iGQZGxcemA+ K+NSC4HdLqcGF721sOUxczQu8xxZyu5njxmbcUvxeDZoxzjA7RgWqtNmKcllF6cZBjmT zp9g== X-Gm-Message-State: AOAM532SWPm4MQKTJDu+8pTpcy1JEkQ/4ZtPbMFyfrpKEvL6O81LV7Dw K4qX+MCWV68PgLf5a6QUg1jTj/Vmbf8= X-Google-Smtp-Source: ABdhPJwQ5OJnle8CekBsThAlmdKMYNHdJDGLiIpsjIjy2JpH014uX0e1XXPqrIRc09bv00+LbG+QyQ== X-Received: by 2002:a5d:4388:: with SMTP id i8mr5662264wrq.340.1632410189746; Thu, 23 Sep 2021 08:16:29 -0700 (PDT) Received: from DESKTOPDJK5SEF ([2a00:23c5:4210:1d01:f000:9cf0:2fa6:1351]) by smtp.gmail.com with ESMTPSA id b207sm5846138wmb.29.2021.09.23.08.16.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Sep 2021 08:16:29 -0700 (PDT) Reply-To: From: "Clive Swan" To: "'SQL Padawan'" Cc: References: <002d01d7b080$1d339060$579ab120$@gmail.com> In-Reply-To: Subject: RE: Get COUNT results from two different columns Date: Thu, 23 Sep 2021 16:16:28 +0100 Message-ID: <003e01d7b08d$fbe00980$f3a01c80$@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQFraaHSipoifrbfbFMrAzNmSsVIDgG64nr0rHxweUA= Content-Language: en-gb List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Greetings, Thanks for the message. The error message that I get is. ERROR:=20 subquery in FROM must have an alias Hint: For example, FROM (SELECT ...) [AS] foo. Position: 100 Trying to make sense of it.. Clive -----Original Message----- From: SQL Padawan [mailto:sql_padawan@protonmail.com]=20 Sent: 23 September 2021 14:50 To: cliveswan@gmail.com Cc: pgsql-general@lists.postgresql.org Subject: RE: Get COUNT results from two different columns Hi, > I have two separate queries that work individually, returning a count = from each column. > I would appreciate any pointers. > new_sup, COUNT(new_sup) AS new_sup_count > old_sup, COUNT(old_sup) AS old_sup_count At least some of your problem is here - in your UNION-ed table, this is = one and the same field and therefore cannot have two different names. HTH, SQL Padawan