Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fUfND-00040o-6q for pgsql-general@arkaria.postgresql.org; Sun, 17 Jun 2018 21:38:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fUfNB-0003IC-M3 for pgsql-general@arkaria.postgresql.org; Sun, 17 Jun 2018 21:38:09 +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.89) (envelope-from ) id 1fUfN9-0003Hw-LY for pgsql-general@lists.postgresql.org; Sun, 17 Jun 2018 21:38:09 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fUfN6-0001Pe-0P for pgsql-general@postgresql.org; Sun, 17 Jun 2018 21:38:06 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 7BA07215AC; Sun, 17 Jun 2018 17:38:02 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sun, 17 Jun 2018 17:38:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=CqITwtE43CSEFmNEG2X9RAVfRAHC4 s2ycv8daXoZh/Q=; b=kRDkl3rPpZx941cAJsPRNQibUDhY4rmchEHoOMMKPe/17 v9oDmEcUTVl3Q4BZCF98fjGhxnaPeYEDF+TeQRTArDhssAshyOqZqaFN9a6yga+h t57HMAhIrJVFf+21R5Z0VyrWoQdH0za2K51xI65D0V/gruJQRMEUY4uUnQV0R1pQ PdJBKFyJAY+Zfy12kep5uHZlifcBOpT3wlqcsIhOedBkH898pqPdELjzKxWVppXd Tf1TsR7MvPskIPcz80mY4E5QsHZUkDZYd6utVGL5WOuJO78/w44QKAIXBghVjU2F XyQZvY/f9ckx0CQMNxeOG5dWnqpDqyr6gkdJ/iwZw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=CqITwt E43CSEFmNEG2X9RAVfRAHC4s2ycv8daXoZh/Q=; b=GJ2NNuV7ROBEVTBultDNPQ 0fdrvil/Awc9b4CI10nMT7vBeFL/OEm7X6OcpCp82UohhUPjw9ERuBl4VJF2i62e koc+7EjYXo/u0lWeuDhjzdvN10n862wj2ACOfEcEfGV5T3lquLo1lJ+3npx8JMZZ o5iWjBNthosFyaDuxSFdJXhcpu7NCS4VhRNVxUU4siMS/ejcw9OEFt+1yaxi0Bsf B0HGjG0v1h7h0pIr2SSfG1Ilr9t4BirsllyE82rBecF1YApBb5s9WRzHkFhX4ksP 2+EUTS8E1yFzUBjjkuxWi4QOmg1z8PeZf9ooWQruHa/17eq9EBxb9vo4Fp/ZUO/A == X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.159.209]) by mail.messagingengine.com (Postfix) with ESMTPA id D5AE9E4649; Sun, 17 Jun 2018 17:38:01 -0400 (EDT) Subject: Re: Check to see if customer exist in second table. Help needs with psql To: Rv02 , pgsql-general@postgresql.org References: <1529263171492-0.post@n3.nabble.com> From: Adrian Klaver Message-ID: <07d7498e-7cc0-ca4f-39d8-b72c9c09cfa7@aklaver.com> Date: Sun, 17 Jun 2018 14:38:00 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <1529263171492-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 06/17/2018 12:19 PM, Rv02 wrote: > > > psql > I have two tables , table A and Table b. Table A has list of about 60000 > customers ID with all their details and Table B had customer is and age for > over 500000 rows of customers. I going to assume you meant Table B has customer ID and age above. Does Table B have duplicate records for customer ID? If so what I offer below might need to be revised. > > I need a query that will take a customer from table a and if that customer > exists in table B then insert a yes in a new column in table a. Basically > what I want to end up with in table a , is all the customers in this table > and if they exist in table B then yes in a column. I.e the final result will > be 60000 customers and additional column at the end with yes or no depending > if they exist in table B. For future reference there are examples below that cover this: https://www.postgresql.org/docs/10/static/sql-update.html " UPDATE employees SET sales_count = sales_count + 1 FROM accounts WHERE accounts.name = 'Acme Corporation' AND employees.id = accounts.sales_person; " I would test on a dev database or at least use: BEGIN; ... COMMIT; Untested: BEGIN; UPDATE a set new_column = 'f'; UPDATE a SET new_column = 't' FROM b WHERE a.id = b.id; ROLLBACK or COMMIT depending on outcome of above. > > Any help is appreciate it > > > > -- > Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html > > -- Adrian Klaver adrian.klaver@aklaver.com