× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Ron,

You don't need to bother with updating via a join.... 

update table1
   set fldX = (select T2.fldY from table2 T2
               where T1.keyfld = T2.keyfld)

Now, there's still a problem with this.... What happens when T1 does not
have a matching row in T2?  (Answer: you'll update fldx to *null, which
probably isn't what you want...  So, there's two ways to handle; define a
default value that you want to see in place of *null, or only update rows
that exist in both tables.  Since your original notion was to use inner
join, I'll proceed with the latter solution.

update table1
   set fldX = (select T2.fldY from table2 T2
               where T1.keyfld = T2.keyfld)
where exists (select * from table2 T3
               where T1.keyfld = T3.keyfld)  

The other alternative looks like this... Remember that this one will change
every row in T1, so be careful that you understand what's happening...

update table1
   set fldX = (select coalesce(T2.fldY,' ') 
               from table2 T2
               where T1.keyfld = T2.keyfld)

hth,

Eric DeLong
Sally Beauty Company
MIS-Project Manager (BSG)
940-297-2863 or ext. 1863



-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx]On Behalf Of Ron Adams
Sent: Monday, January 16, 2006 3:30 PM
To: MIDRANGE-L@xxxxxxxxxxxx
Subject: Re: SQL UPDATE using INNER JOIN?


To be more specific, I'm trying to do the equivalent of this on the iSeries:


update table1
   set fldX = T2.fldY
  from table1 T1
inner
  join table2 T2
    on T1.keyfld = T2.keyfld






On 1/16/06, Ron Adams <rondadams@xxxxxxxxx> wrote:
>
> I'm trying to don an UPDATE to a table using data from another table and
> using the INNER JOIN clause. Can anyone show me a working example of this
> because I can't seem to get it right.
>
>

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.