Received: from shaked.cc.openu.ac.il (shaked.cc.openu.ac.il [147.233.145.65]) by hub.org (8.9.1/8.9.1) with ESMTP id GAA17153 for ; Tue, 24 Nov 1998 06:26:42 -0500 (EST) (envelope-from herouth@oumail.openu.ac.il) Received: from [147.233.159.109] (herouth@mac-herouth.pc.openu.ac.il [147.233.159.109]) by shaked.cc.openu.ac.il (8.8.8/8.8.8) with ESMTP id NAA22995; Tue, 24 Nov 1998 13:26:33 +0200 (IST) X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Tue, 24 Nov 1998 13:27:30 +0200 To: s-fery@kkt.sote.hu, Postgresql sql From: Herouth Maoz Subject: Re: [SQL] select in update At 12:05 +0200 on 24/11/98, Engard Ferenc wrote: > Well, then a little bit complex problem: > two tables: A (var), B (var1,var2). I would like to replace the A.var > if it exists in B.var2 with B.var1. Is it good? > > UPDATE a > SET a.var=b.var1 > FROM b <-- or maybe I need to put 'a' here too? > WHERE a.var=b.var2; > > I don't need to tell that there are rows which cannot find in B? (In > this case it shouldn't change.) It's a bit hard to understand what you want to be done, and what you *don't* want to be done. The above seems to be the right update. But you better give a short example of what you want. In the example you gave, if the data is: A == 1 2 3 4 B == var1 var2 ==== ==== 10 1 30 3 50 5 Then after the update, A will be: 10 2 30 4 This is because 1 and 3 were matched, and 2 and 4 weren't matched. If that is what you wanted, then your update statement is correct. Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma