pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: s-fery@kkt.sote.hu, Postgresql sql <pgsql-sql@postgreSQL.org>
Subject: Re: [SQL] select in update
Date: Tue, 24 Nov 1998 13:27:30 +0200
Message-ID: <l03110700b28047415e6d@[147.233.159.109]> (raw)
In-Reply-To: <Pine.LNX.3.96.981124104050.6087C-100000@Pons.sote.hu>
References: <l03110700b28020eb5be7@[147.233.159.109]>

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





view thread (4+ messages)

Message-ID: <l03110700b28047415e6d@[147.233.159.109]>
Permalink:  ../l03110700b28047415e6d@%5B147.233.159.109%5D/
Also on:    postgresql.org/message-id/l03110700b28047415e6d@[147.233.159.109]

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: herouth@oumail.openu.ac.il
  Subject: Re: [SQL] select in update
  In-Reply-To: <l03110700b28047415e6d@[147.233.159.109]>
  References: <l03110700b28020eb5be7@[147.233.159.109]> <l03110700b28047415e6d@[147.233.159.109]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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