473,549 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update with join statement not working in DB2

------------------------
UPDATE A
SET A.ID = '?' + A.ID
FROM TABLEA A
LEFT OUTER JOIN TABLEB B ON
A.INDEX = B.INDEX
WHERE B.DUP_ID IS NULL
------------------------

seems like update with join statement not working in DB2 version 5

any idea to update duplicated 'ID' without joining table and "where....
in" statement ??

Sep 21 '06 #1
5 15492
Sphenix wrote:
------------------------
UPDATE A
SET A.ID = '?' + A.ID
FROM TABLEA A
LEFT OUTER JOIN TABLEB B ON
A.INDEX = B.INDEX
WHERE B.DUP_ID IS NULL
------------------------

seems like update with join statement not working in DB2 version 5

any idea to update duplicated 'ID' without joining table and "where....
in" statement ??
DB2 Version 5? I hope you are talking about DB2 V5R? for iSeries.
Let me clarify the intent here:
You want to prepend a '?' to all IDs for which there is NO match in B?
Is B.DUP_ID nullable?

UPDATE TABLEA A
SET A.ID = '?' || A.ID
WHERE NOT EXISTS(SELECT 1 FROM TABLEB B WHERE A.INDEX = B.INDEX)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 21 '06 #2
DB2 Version 5? I hope you are talking about DB2 V5R? for iSeries.
Let me clarify the intent here:
You want to prepend a '?' to all IDs for which there is NO match in B?
Is B.DUP_ID nullable?

UPDATE TABLEA A
SET A.ID = '?' || A.ID
WHERE NOT EXISTS(SELECT 1 FROM TABLEB B WHERE A.INDEX = B.INDEX)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
above statement can be use, however my friend said not recommended to
update a table where have another select statement

e.g.
UPDATE TABLEA A
SET A.ID = '?' || A.ID
WHERE NOT EXISTS(SELECT 1 FROM TABLEB B WHERE A.INDEX = B.INDEX)
or
UPDATE TABLEA A
SET A.ID = '?' || A.ID
WHERE A.ID NOT IN (SELECT B.ID FROM TABLEB B WHERE A.INDEX =
B.INDEX)

-----------------
TABLEA
------------------
INDEX ID
1 A
2 B
3 B --Duplicated Record
4 D
5 E
6 E --Duplicated Record
7 G
8 H
9 J
10 J --Duplicated Record
------------------

so my task is update duplicated record of ID with '?' on the biggest
number of INDEX
so my result should be INDEX 3, 6 & 10 with '?' infront the ID

Sep 22 '06 #3
Sphenix wrote:
>DB2 Version 5? I hope you are talking about DB2 V5R? for iSeries.
Let me clarify the intent here:
You want to prepend a '?' to all IDs for which there is NO match in B?
Is B.DUP_ID nullable?

UPDATE TABLEA A
SET A.ID = '?' || A.ID
WHERE NOT EXISTS(SELECT 1 FROM TABLEB B WHERE A.INDEX = B.INDEX)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/

above statement can be use, however my friend said not recommended to
update a table where have another select statement

e.g.
UPDATE TABLEA A
SET A.ID = '?' || A.ID
WHERE NOT EXISTS(SELECT 1 FROM TABLEB B WHERE A.INDEX = B.INDEX)
or
UPDATE TABLEA A
SET A.ID = '?' || A.ID
WHERE A.ID NOT IN (SELECT B.ID FROM TABLEB B WHERE A.INDEX =
B.INDEX)

-----------------
TABLEA
------------------
INDEX ID
1 A
2 B
3 B --Duplicated Record
4 D
5 E
6 E --Duplicated Record
7 G
8 H
9 J
10 J --Duplicated Record
------------------

so my task is update duplicated record of ID with '?' on the biggest
number of INDEX
so my result should be INDEX 3, 6 & 10 with '?' infront the ID
That is definitely NOT what that SQL Server query you posted is doing.
Aside where is TABLEB? You only posted half the data!
Here is what does the job given the TABLEA you posted:
CREATE TABLE TABLEA(INDEX INT, ID VARCHAR(10));
INSERT INTO TABLEA VALUES
(1 , 'A'),
(2 , 'B'),
(3 , 'B'),
(4 , 'D'),
(5 , 'E'),
(6 , 'E'),
(7 , 'G'),
(8 , 'H'),
(9 , 'J'),
(10, 'J');

UPDATE TABLEA A
SET ID = '?' || ID
WHERE EXISTS(SELECT 1 FROM TABLEA B
WHERE A.ID = B.ID
AND A.INDEX B.INDEX);

SELECT * FROM TABLEA;
INDEX ID
----------- ----------
1 A
2 B
3 ?B
4 D
5 E
6 ?E
7 G
8 H
9 J
10 ?J

10 record(s) selected.

In DB2 V8.2 for LUW (I still don't know which platform you are using)
you can write this, which is much faster:
UPDATE
(SELECT ID,
ROWNUMBER() OVER(PARTITION BY ID ORDER BY INDEX) AS rn
FROM TABLEA) AS U
SET ID = '?' || ID
WHERE rn 1;

Cheers
Serge

PS: I never ask my friends for SQL advise ;-)
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 22 '06 #4
UPDATE
(SELECT ID,
ROWNUMBER() OVER(PARTITION BY ID ORDER BY INDEX) AS rn
FROM TABLEA) AS U
SET ID = '?' || ID
WHERE rn 1;
I think i'm using "Version 5 Release 3 Modification Level 0"
btw the code above is not supported.... :(

Sep 22 '06 #5
Sphenix wrote:
>UPDATE
(SELECT ID,
ROWNUMBER() OVER(PARTITION BY ID ORDER BY INDEX) AS rn
FROM TABLEA) AS U
SET ID = '?' || ID
WHERE rn 1;

I think i'm using "Version 5 Release 3 Modification Level 0"
btw the code above is not supported.... :(
Correct, DB2 V5R3 for iSeries doesn't have OLAP.
But the EXISTS query will work.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
23686
by: ajay | last post by:
How to write a single update sql statement to update different set of attributes of a table. In other words what will be the value of indicator variables to ignore updates of some attributes in a update statement. e.g. EXEC SQL UPDATE vA:iA vB:iB vC:iC in TABLE 1 where vD = ...
3
8408
by: Alex | last post by:
Hi folks, Hopefully this is a simple fix, but I keep getting Syntax error with this statement in an MS SQL DTS statement and in Query Analyzer: Update A Set A.deptcode = A.deptcode, A.type = A.Type, a.TotalExpenseUnit = (a.LaborExpenseUnit + a.OtherExpenseUnit) Where a.Type in ('FYTD04', 'Prior Year','Budget') From Data_Unsorted A Join...
5
1941
by: Zeno | last post by:
Hi......... Its been awhile since I've touched SQL statements, so I need some help with writing a JOIN statement to query 3 tables. The dB has 3 tables with values Applications -Application_code(Primary key) -Application_name
3
1577
by: Jack Smith | last post by:
Hello, I want to be able to view data from 3 tables using the JOIN statement, but I'm not sure of how to do it. I think i don't know the syntax of the joins.I imagine this is easy for the experienced - but Im not. Allow me to explain: I have 2 Tables: PERSON and SIGN PERSON
2
1742
by: kevinjbowman | last post by:
I have the following query I wrote in MySQL 5.0 Select eq_employees.empid, eq_sigreturns.returnid From eq_employees Left Join eq_sigreturns ON eq_employees.empid = eq_sigreturns.empid
5
1837
by: ltansey | last post by:
I have a problem concerning a join statement query, the two table are called PublicHouse & PublicHouseBeer, below are the following tables are there attributes; PublicHouse Table create table "PublicHouse" (PublicHouseID char (20), PubName Char (20), Address varchar (20), Town char (20), County varchar (20));
2
1397
by: ltansey | last post by:
Simple Join Statement Help -------------------------------------------------------------------------------- I have a problem concerning a join statement query, the two table are called PublicHouse & PublicHouseBeer, below are the following tables are there attributes; PublicHouse Table create table "PublicHouse" (PublicHouseID char...
4
1625
by: linendra | last post by:
Hi i am using oracle 8i. when i execute the join statement i got the error message. at the same time when i execute the same code to sql server and ms access the code execute successfully. i am not a regular user of oracle. hance i thougth that the join statement for orcle might be different. please help me to solve this problem or...
16
2186
by: rebecky via AccessMonster.com | last post by:
Can anyone help with this statement? I get a syntax error message.....not good at this at all. Thanks DoCmd.RunSQL "Update JOTable" _ & "INNER JOIN ON JOTable.JOID = . JOID " _ & "Set .ActEndDate = "jotable.ActEndDate "" _ & "WHERE (((.JOID)=!! .form.));"
0
7467
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7982
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7827
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6066
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5385
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3494
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1961
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1079
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.