Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1brcze-0005Dz-My for pgsql-general@arkaria.postgresql.org; Wed, 05 Oct 2016 03:35:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1brczd-0002lz-Mu for pgsql-general@arkaria.postgresql.org; Wed, 05 Oct 2016 03:35:41 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1brczc-0002l5-8I for pgsql-general@postgresql.org; Wed, 05 Oct 2016 03:35:40 +0000 Received: from mail-it0-x22a.google.com ([2607:f8b0:4001:c0b::22a]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1brczZ-0005Kh-4J for pgsql-general@postgresql.org; Wed, 05 Oct 2016 03:35:38 +0000 Received: by mail-it0-x22a.google.com with SMTP id o19so150370264ito.1 for ; Tue, 04 Oct 2016 20:35:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=8Cp/FikEdVcKQ3bSHhfjxX/ggKP+uSo6uua7JMxX+bI=; b=AB9Ka5F7c0/A1HDQPeWrZukfVhmLauEHnWEYer8k1EzGkBX5vHWLW7E81tOt15ycWS h5HgWcMR9DStlRx1kLpSqN4JBVdyE34EWzvH4BrXvYpDoKIGh4dcEXZ9qw64MvwAldX/ NXSu4f9qsxH/e0CzaGhVlxkoGD11Ob7pGlQCw3m8cgKHS+KPvLDr/P83H4qhDSN9Vk0I X8+UPu9l9Pq2hHOXT+ERpeYLusAhvR1iuVpFNQPOKheDlEF0cQU1euKGp5zW0pMyx9It 2phbc/TLdG+aXvM+i1kSyOPExXvgb3Pn4d0BARlm1UvZE5PObmZVcZwNN8rhrDA43xgx F1rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=8Cp/FikEdVcKQ3bSHhfjxX/ggKP+uSo6uua7JMxX+bI=; b=G6PfHNbyIqTNO/tO/MVlroS7h3I1AoWD8HKYluwqAmGl2t016fU4FPJiNGydQnXFLU 3j4UgYVKvcIB+XZ/Ew++LSau/4T8mu7A48u6Wok5RY0McV0oAN5L12LXteHPzZcBbkSA ULf4GaPGOkVwEKSg0c0aM/0P/7m5sqWT1vdbDJa8h6+kK2fSPqsSxDp7zM0Xrx/Kdlqs LRxmiPb5IwYxUfY6JcIbmuDlQ6Z3hSPb9HBbWLE/XM0xU0aQPMd7kJeV4ZPVsG8zpYu3 XkPcEVCDp/7OLiqZO+7gI6jygiE6+QX6eSrcK1vqTxFHeF9NTnj0riF+yCNtGMOazdhI YeDA== X-Gm-Message-State: AA6/9Rln8MmxZNUZjfnLblvS7cbG6N1KlS98khklA7UJFYBLLuZ4XDab6mGqkHDix2BdmQ== X-Received: by 10.107.138.204 with SMTP id c73mr9119810ioj.192.1475638535903; Tue, 04 Oct 2016 20:35:35 -0700 (PDT) Received: from [192.168.1.147] (c-98-202-89-42.hsd1.ut.comcast.net. [98.202.89.42]) by smtp.gmail.com with ESMTPSA id l188sm2891735iol.37.2016.10.04.20.35.34 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Oct 2016 20:35:35 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: Query help From: Rob Sargent In-Reply-To: <1475638265.3904.12.camel@centos65.machinemanagement.com> Date: Tue, 4 Oct 2016 21:35:38 -0600 Cc: PostgreSQL General Content-Transfer-Encoding: quoted-printable Message-Id: <9DC7FCC4-2B31-4578-BA08-4F4098DB11AF@gmail.com> References: <1475638265.3904.12.camel@centos65.machinemanagement.com> To: bret_stern@machinemanagement.com X-Mailer: Apple Mail (2.3124) X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org > On Oct 4, 2016, at 9:31 PM, Bret Stern = wrote: >=20 > Good evening, > I'm curious about a way to ask the following question of my vendors > table. >=20 > psuedo1 "select all vendors which exist in BUR and EBC and SNJ" >=20 > and > psuedo2 "select all vendors which DO NOT exist in all three show rooms >=20 >=20 > The data is from a Sage accounting system which I pull out and place in a > pg db. What we are trying to do is identify which vendors are defined in > all three of our showrooms, and vice-versa, which ones are not. >=20 > ap_vendors table > company_code character varying(10) NOT NULL, > ap_division_no character varying(2) NOT NULL, > vendor_no character varying(7) NOT NULL, > terms_code character varying(2), > vendor_name character varying(30), > address_line1 character varying(30), > address_line2 character varying(30), > address_line3 character varying(30), > city character varying(20), > state character varying(2), > zip_code character varying(10), > telephone_no character varying(17), > fax_no character varying(17), > CONSTRAINT ap_vendors_pk PRIMARY KEY (company_code, ap_division_no, ven= dor_no) >=20 > sample records: > "BUR";"00";"ADEXU";"30";"ADEX USA";"''";"''";"''";"''";"''";"92831";"''";= "''" > "BUR";"00";"AGORA";"30";"Agora Natural Surfaces";"''";"''";"''";"''";"''"= ;"90248";"''";"''" > "BUR";"00";"AKDOP";"30";"AKDO Pacific";"''";"''";"''";"''";"''";"94545";"= ''";"''" > "EBC";"00";"ADEXU";"30";"ADEX USA";"''";"''";"''";"''";"''";"92831";"''";= "''" > "EBC";"00";"AGORA";"30";"Agora Natural Surfaces";"''";"''";"''";"''";"''"= ;"90248";"''";"''" > "EBC";"00";"ARIZ01";"30";"Arizona Tile";"''";"''";"''";"''";"''";"94550";= "''";"''" > "SNJ";"00";"AKDOP";"30";"AKDO Pacific";"''";"''";"''";"''";"''";"94545";"= ''";"''" > "SNJ";"00";"AGORA";"30";"Agora Natural Surfaces";"''";"''";"''";"''";"''"= ;"90248";"''";"''" > "SNJ";"00";"ADEXU";"30";"ADEX USA";"''";"''";"''";"''";"''";"92831";"''";= "''" >=20 > What I need is a query which I can modify to return only vendors which ex= ists > in all three company_code columns ( BUR, EBC, SNJ) (they represent showro= om location) >=20 > eg; exists in BUR, EBC, SNJ > ADEXU > AGORA >=20 > OR >=20 > modify the query to return only the vendors which DO NOT exist in all > three showrooms based on the first column company_code >=20 > eg;=20 > AKDOP only exists in BUR and SNJ > ARIZ01 only exists in EBC >=20 > Thanks > Bret >=20 >=20 Not sure I like the schema but=20 select vendor_no, count(*) from ap_vendors having count(*) =3D 3; and maybe count(*) < 3 is your second answer. --=20 Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general