Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1brctO-0004dW-FN for pgsql-general@arkaria.postgresql.org; Wed, 05 Oct 2016 03:29:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1brctN-0002Ts-ST for pgsql-general@arkaria.postgresql.org; Wed, 05 Oct 2016 03:29:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1brcr3-0008JE-N1 for pgsql-general@postgresql.org; Wed, 05 Oct 2016 03:26:49 +0000 Received: from machinemanagement.com ([204.42.157.20]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1brcr0-0004py-2w for pgsql-general@postgresql.org; Wed, 05 Oct 2016 03:26:48 +0000 Received: from [192.168.40.16] (70-90-161-90-ca.sfba.hfc.comcastbusiness.net [70.90.161.90]) (authenticated bits=0) by machinemanagement.com (8.14.5/8.13.1) with ESMTP id u953QasX008108 for ; Tue, 4 Oct 2016 20:26:39 -0700 Subject: Query help From: Bret Stern Reply-To: bret_stern@machinemanagement.com To: PostgreSQL General Content-Type: multipart/alternative; boundary="=-mmRbUhLIVqXVNq5IFAqO" Organization: Machine Management Date: Tue, 04 Oct 2016 20:31:05 -0700 Message-ID: <1475638265.3904.12.camel@centos65.machinemanagement.com> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 (2.32.3-36.el6) X-Pg-Spam-Score: -3.1 (---) 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 --=-mmRbUhLIVqXVNq5IFAqO Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Good evening, I'm curious about a way to ask the following question of my vendors table. psuedo1 "select all vendors which exist in BUR and EBC and SNJ" and psuedo2 "select all vendors which DO NOT exist in all three show rooms 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. 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, vendor_no) 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";"''";"''" What I need is a query which I can modify to return only vendors which exists in all three company_code columns ( BUR, EBC, SNJ) (they represent showroom location) eg; exists in BUR, EBC, SNJ ADEXU AGORA OR modify the query to return only the vendors which DO NOT exist in all three showrooms based on the first column company_code eg; AKDOP only exists in BUR and SNJ ARIZ01 only exists in EBC Thanks Bret --=-mmRbUhLIVqXVNq5IFAqO Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 7bit Good evening,
I'm curious about a way to ask the following question of my vendors
table.

psuedo1 "select all vendors which exist in BUR and EBC and SNJ"

and
psuedo2 "select all vendors which DO NOT exist in all three show rooms


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.

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, vendor_no)

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";"''";"''"

What I need is a query which I can modify to return only vendors which exists
in all three company_code columns ( BUR, EBC, SNJ) (they represent showroom location)

eg; exists in BUR, EBC, SNJ
ADEXU
AGORA

OR

modify the query to return only the vendors which DO NOT exist in all
three showrooms based on the first column company_code

eg;
AKDOP only exists in BUR and SNJ
ARIZ01 only exists in EBC

Thanks
Bret


--=-mmRbUhLIVqXVNq5IFAqO--