X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id A6DCC9FB270 for ; Fri, 28 Jul 2006 18:30:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 91683-01 for ; Fri, 28 Jul 2006 18:30:01 -0300 (ADT) X-Greylist: delayed 00:05:01.124636 by SQLgrey- Received: from mail.e-lumo.com (waxaale.e-lumo.com [81.169.187.115]) by postgresql.org (Postfix) with ESMTP id 893389FB277 for ; Fri, 28 Jul 2006 18:30:01 -0300 (ADT) Received: from [10.100.100.10] ([10.100.100.10]) by mail.e-lumo.com with esmtp; Fri, 28 Jul 2006 21:24:57 +0000 id 00033C0E.44CA80A9.000059C0 Mime-Version: 1.0 (Apple Message framework v752.2) Content-Transfer-Encoding: 7bit Message-Id: Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed To: pgsql-sql@postgresql.org From: Fabian Peters Subject: UPDATE with WHERE clause on joined table Date: Fri, 28 Jul 2006 23:24:56 +0200 X-Mailer: Apple Mail (2.752.2) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/364 X-Sequence-Number: 25938 Hi, I'm only very rarely using SQL, so please forgive me if I show any obvious signs of ignorance... I've got three tables "customer", "address" and "country". I want to set the "language" attribute on "customer" on rows returned by a SELECT such as this: SELECT title, first_names, last_name, email, language, country.country_name FROM ((customer JOIN address ON customer.eoid = address.eoid_customer) JOIN country ON address.eoid_country = country.eoid) WHERE email LIKE '%.es' AND country.country_name = 'SPAIN'; That is, I want to set the "language" to 'Spanish' where the "customer.email" is like '%.es' and where "country.country_name" is 'SPAIN'. I've tried all sorts of places to put the JOIN and the WHERE clauses within the UPDATE statement, but I just don't get it. I'd be most grateful for any help... TIA Fabian P.S.: One of my sorry attempts looked like this - which updates all rows in "customer" so I figure the WHERE clause is not where it should be: UPDATE customer SET language = 'Spanish' FROM ((customer AS customer_address JOIN address ON customer_address.eoid = address.eoid_customer) JOIN country ON address.eoid_country = country.eoid) WHERE customer.email LIKE '%.es' AND country.country_name = 'SPAIN');