Re: Update SQL using joins

From: Noel <tbal_at_go2.pll-l>
Date: Thu, 21 Apr 2005 14:10:38 +0200
Message-ID: <d485a3$9q7$1_at_inews.gazeta.pl>


Użytkownik Phil napisał:

> I'm seriously missing something here and i'm wondering if someone can
> help me understand it.
>
> I have 2 tables. Table p contains 1,400 records, table m contains
> 470,000 records. I want to modify the 1,400 records in table m that
> corrsepond to all the 1,400 records in table p. Here's what i've
> tried,
>
> UPDATE m
> SET len = (SELECT units
> FROM p
> WHERE m.bkseq = p.bkseq)
>
Same:

UPDATE m

    SET l = 5;

> I thought that the WHERE clause would ensure that only records with the
> same bkseq in both tables would be changed, = 1,400. In stead 470,000
> records in m are changed. Why? Do i really have to add a second where
> clause at the end,
>
> WHERE bkseq IN (SELECT bkseq
> FROM p
> WHERE p.bkseq = m.bkseq)
>

Yes, you have to do it.

-- 
Noel
Received on Thu Apr 21 2005 - 14:10:38 CEST

Original text of this message