Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 1E6412E0074 for ; Wed, 2 Apr 2008 17:48:24 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 88202-01 for ; Wed, 2 Apr 2008 17:48:01 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from vsmtp21.tin.it (vsmtp21.tin.it [212.216.176.109]) by developer.postgresql.org (Postfix) with ESMTP id 779002E0050 for ; Wed, 2 Apr 2008 17:48:00 -0300 (ADT) Received: from kerberos.webthatworks.it (82.48.130.181) by vsmtp21.tin.it (7.3.122) id 47AB330F02E0529B for pgsql-sql@postgresql.org; Wed, 2 Apr 2008 22:47:55 +0200 Received: from stige.webthatworks.it (dark.webthatworks.it [192.168.1.9]) by kerberos.webthatworks.it (Postfix) with ESMTP id 5020FE6A96 for ; Wed, 2 Apr 2008 22:47:55 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by stige.webthatworks.it (Postfix) with ESMTP id EE163578FC for ; Wed, 2 Apr 2008 22:47:53 +0200 (CEST) Date: Wed, 2 Apr 2008 22:47:53 +0200 From: Ivan Sergio Borgonovo To: pgsql-sql@postgresql.org Subject: update with join Message-ID: <20080402224753.78f454fc@webthatworks.it> Organization: www.WebThatWorks.it X-Mailer: Claws Mail 3.3.1 (GTK+ 2.12.9; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200804/10 X-Sequence-Number: 30549 I've create table types( typeid int, special boolean not null ); create table methods( methodid int, typeid references types(typeid), ); create table orders( orderid int ); create table order_payments( payid int orderid references order(orderid), methodid references method(methodid), issued boolean not null default false ); orderid payid methodid special 1 1 1 t 1 2 2 t 1 3 3 t 1 4 4 f 1 5 4 f I'd like to chose one payid If the payid is "special" just set issued to true for that payid, leave the other unchanged. If the payid is not "special" set issued for all the payid in the same order. eg. So if payid=4 I'd have orderid payid methodid special issued 1 1 1 t t 1 2 2 t t 1 3 3 t t 1 4 4 f t 1 5 4 f t and if payid=2 orderid payid methodid special issued 1 1 1 t f 1 2 2 t t 1 3 3 t f 1 4 4 f f 1 5 4 f f This stuff below doesn't work: update order_payments set issued=true where payid in ( select p.payid from order_payments p join methods as m on m.methodid=p.methodid join types as t on m.typeid=t.typeid where (p.orderid=%d and not t.special) or p.payid=%d); and I can understand why but I can't rewrite it to make it work. thanks -- Ivan Sergio Borgonovo http://www.webthatworks.it