------------------------
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 ?? 5 15515
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/
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
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/
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.... :(
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/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 = ...
|
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 Data_Unsorted B On
|
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
|
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
|
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
| |
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));
|
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 (20),
PubName Char (20),
|
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 provide me the sample of join statement which execute successfully on oracle 8i
|
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.));"
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |