Groups > DB2 > DB2 on AS400 server > Re: UPDATE using a join




UPDATE using a join

UPDATE using a join
Mon, 03 Dec 2007 14:31:24 EST
Hi There,<br />
<br />
I have a requirement to update two fields in one file (keyed by SKUID), based on
a value in another file (SKUID).<br />
<br />
ie.  Table 1 (SKUID, Field1, Field2)<br />
     Table 2 (SKUID) (Contains 21000 records)<br />
<br />
I wrote a Stored Procedure that reads a record from Table 2, and based on the
SKUID value I update the Field1 and Field2 of Table 1 to 'D' and 'Y'
respectively.<br />
<br />
What I wanted to try to get working was to do the same thing, but from a single
SQL statement.  Something like:<br />
<br />
UPDATE LIBRARY1.TABLE1 T SET FIELD1 = 'D',<br />
FIELD2 = 'Y' WHERE T.SKUID = (SELECT DISTINCT SKUID FROM  <br />
LIBRARY2.TABLE2)  <br />
<br />
It comes back with  'Result of SELECT more than one row', which I understand,
but is there a way to do this?<br />
<br />
Post Reply
Re: UPDATE using a join
Mon, 3 Dec 2007 21:06:42 -0500
Like this, mabye?
    UPDATE LIBRARY1.TABLE1 T SET FIELD1 = 'D', FIELD2 = 'Y'
    WHERE T.SKUID IN  -- <====  replaced "=" with "IN"
    (SELECT DISTINCT SKUID FROM LIBRARY2.TABLE2)

Sam

<omar.pricca@marks.com> wrote in message 
news:23561794.1196710315113.JavaMail.wassrvr@ltsgwas009.sby.ibm.com...
> Hi There,<br />
> <br />
> I have a requirement to update two fields in one file (keyed by SKUID), 
> based on a value in another file (SKUID).<br />
> <br />
> ie.  Table 1 (SKUID, Field1, Field2)<br />
>     Table 2 (SKUID) (Contains 21000 records)<br />
> <br />
> I wrote a Stored Procedure that reads a record from Table 2, and based on 
> the SKUID value I update the Field1 and Field2 of Table 1 to 'D' and 'Y' 
> respectively.<br />
> <br />
> What I wanted to try to get working was to do the same thing, but from a 
> single SQL statement.  Something like:<br />
> <br />
> UPDATE LIBRARY1.TABLE1 T SET FIELD1 = 'D',<br />
> FIELD2 = 'Y' WHERE T.SKUID = (SELECT DISTINCT SKUID FROM  <br />
> LIBRARY2.TABLE2)  <br />
> <br />
> It comes back with  'Result of SELECT more than one row', which I 
> understand, but is there a way to do this?<br />
> <br />
> Thanks in advance for any suggestions! 

Post Reply
Re: UPDATE using a join
Tue, 04 Dec 2007 11:51:31 EST
Hi Sam,<br />
<br />
Post Reply
about | contact