Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 5936F2E0037 for ; Wed, 21 Nov 2007 22:59:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 90864-06 for ; Wed, 21 Nov 2007 22:58:48 -0400 (AST) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by postgresql.org (Postfix) with SMTP id 536952E0032 for ; Wed, 21 Nov 2007 22:58:54 -0400 (AST) Received: (qmail invoked by alias); 22 Nov 2007 02:58:51 -0000 Received: from i3ED6DBD3.versanet.de (EHLO [192.168.0.112]) [62.214.219.211] by mail.gmx.net (mp058) with SMTP; 22 Nov 2007 03:58:51 +0100 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX1+P59V1hrePj9qKZFXJZu2Nou9nXjyRgGewyGDiUC Z4/wq7jZlPafBy Message-ID: <4744F06A.8080302@gmx.net> Date: Thu, 22 Nov 2007 03:58:50 +0100 From: Andreas User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; de-AT; rv:1.8.1.9) Gecko/20071030 SeaMonkey/1.1.6 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: update on join ? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/105 X-Sequence-Number: 29633 Hi, I'd like to update a table efficiently where the relevant select-info is in another table that is foreign-linked. Stupid example. 2 tables: things (thing_id integer, name varchar(100), color varchar(100)) inventory (item_id integer, thing_fk integer references things (thing_id), number) For some reason I'd want to set the number of every red item to 0. This inventory doesn't contain the color but the foreign key to the other table where the color is found. I tried UPDATE things JOIN inventory ON things.thing_id = inventory.thing_fk SET number = 0 WHERE color = 'red' PSQL didn't like the JOIN though. It works like this: UPDATE inventory SET number = 0 WHERE thing_fk IN (SELECT thing_id FROM things WHERE color = 'red') It's effective but is it efficient, too? Regards