pg.ddx.io pgsql-general@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Check to see if customer exist in second table. Help needs with psql 2+ messages / 2 participants [nested] [flat]
* Check to see if customer exist in second table. Help needs with psql @ 2018-06-17 19:19 Rv02 <v.razaghzadeh@gmail.com> 2018-06-17 21:38 ` Re: Check to see if customer exist in second table. Help needs with psql Adrian Klaver <adrian.klaver@aklaver.com> 0 siblings, 1 reply; 2+ messages in thread From: Rv02 @ 2018-06-17 19:19 UTC (permalink / raw) To: pgsql-general 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 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. Any help is appreciate it -- Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Check to see if customer exist in second table. Help needs with psql 2018-06-17 19:19 Check to see if customer exist in second table. Help needs with psql Rv02 <v.razaghzadeh@gmail.com> @ 2018-06-17 21:38 ` Adrian Klaver <adrian.klaver@aklaver.com> 0 siblings, 0 replies; 2+ messages in thread From: Adrian Klaver @ 2018-06-17 21:38 UTC (permalink / raw) To: Rv02 <v.razaghzadeh@gmail.com>; pgsql-general 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 ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2018-06-17 21:38 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2018-06-17 19:19 Check to see if customer exist in second table. Help needs with psql Rv02 <v.razaghzadeh@gmail.com> 2018-06-17 21:38 ` Adrian Klaver <adrian.klaver@aklaver.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox