473,770 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

update from a select

I use the following SQL statment to bring z_emp_id values to a
employee table:

update employee set z_emp_id =
(select z.emp_id from z.employee z where z.login=employe e.login)

Upon executing this statement a warning appears (in AQT) saying all
the rows in the table will be modified.

Is this a benign message?

I would expect a warning, if any, to say how many rows would change.

The results (100 or so modified rows) appears to be correct.

I'd like to create an alternative SQL statment, something like:

update employee
set z_emp_id = z.emp_id
from (select emp_id from z.employee z where z.login in (select login
from z.employee)) z
where login = z.login

where z_emp_id is assigned from the z select.

This statement fails because DB2 doesn't understand FROM in this
context.

Might someone be so kind as to suggest a SQL statement that doesn't
impact all rows and has cleaner syntax?

Thanks.

Jul 12 '07 #1
2 18136
gi************* ******@yahoo.co m wrote:
I use the following SQL statment to bring z_emp_id values to a
employee table:

update employee set z_emp_id =
(select z.emp_id from z.employee z where z.login=employe e.login)
MERGE INTO employee
USING z.employee as z
ON z.login=employe e.login
WHEN MATCHED THEN UPDATE SET z_emp_id = z.emp_id

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jul 12 '07 #2
On Thu, 12 Jul 2007 12:31:30 -0700, "gi************ *******@yahoo.c om"
<gi************ *******@yahoo.c omwrote:
>update employee set z_emp_id =
(select z.emp_id from z.employee z where z.login=employe e.login)

Upon executing this statement a warning appears (in AQT) saying all
the rows in the table will be modified.
Of course. The UPDATE has no WHERE clause, so there is nothing
excluding rows. Ergo, all rows will be hit. If it doesn't find a
match, it will SET it to NULL. Which, depending on the strategy, might
be a "Good Thing"(tm). Especially if it had a value that shouldn't be
there.

If you only want to hit the rows where there is a value found, use
WHERE EXISTS and repeat the subquery.
>update employee
set z_emp_id = z.emp_id
from (select emp_id from z.employee z where z.login in (select login
from z.employee)) z
where login = z.login
The FROM's sub-select is redundant. And, the FROM itself is not part
of an UPDATE statement. This is a database, not SQL Server.

B.
Jul 13 '07 #3

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

Similar topics

0
15004
by: Murali | last post by:
Hi All I was reading thro the posting(s) of Thomas Kyte and his nifty approach to doing updates without the need for unnecessary correlated subqueries. An alternative to correlated subquery using this technique is: update ( select columnName, value from name, lookup
3
1705
by: SINTECO - Andrea Tartaglia - NEWS | last post by:
Hallo all, I'm quite new to SQL and I have a problem updating some fields in a table, maybe some of you in this forum can help me! This SELECT statement returns the records that I need to update: select * from A, B where A.a = 'D' and A.b = 'D ' and A.c = B.c and A.d = B.d
9
3209
by: zMisc | last post by:
When I try to update record, I kept getting this error: Row cannot be located for updating. Some values may have been changed since it was last read. No other users are accessing the database - only 1 user is accessing the database. I open the data using adLockOptimistic locking.
5
2599
by: devi | last post by:
hi, I am creating a simple bug tracker application (in Access db) and i created a hisotry table to log the bug history. The history table contains details like ProblemRecordNo (PRN), RecordStatus, Assignee, Reporter (and also some more columns). The PK for this table is ID. It contains multiple entries for a Record.
5
8341
by: parwal.sandeep | last post by:
Hello grp! i'm using INNODB tables which are using frequently . if i fire a SELECT query which fetch major part of table it usually take 10-20 seconds to complete. in mean time if any UPDATE qry comes for a perticular row which is part of SELECT qry i want to know that whether UPDATE will wait for completing SELECT qry or not, or it simply executing without bothering SELECT qry .
2
12544
by: shorti | last post by:
Hello again. I previously inquired about updating 1000 records at a time in a script (not using cursors). Now I have to take it one step further. I want to update records from two different records at once. I have half of the step done but cant seem to fit the seconds part in anywhere: db2 "update (select * from EMPLOY where NAME IN (select NAME from ACCOUNT where IDSTATUS <-1 fetch first 1000 rows only)) set WORKIN='N',...
5
15515
by: Sphenix | last post by:
------------------------ 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
5
2178
by: explode | last post by:
I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String) that creates a new oledbDataAdapter with insert update select and delete commads. I also added that commands can change depending how many columns are in a Table. I add a new column with this code: Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try...
11
3159
by: cooperkuo | last post by:
Dear all, I have a question about ADO in the subform. I know how to use ADO to insert/update/select data into the sigin form, but wehn I try to do it in the form with subform((Datasheet). I don't have any idea how to insert/update/select the recordset data into the subform(Datasheet), especially insert/update. Would someone can give me a idea or sample code to me? Appreciate your help. OS: windows XP +SP2+ Access 2003+SP2 Database: MS...
3
2278
by: modernshoggoth | last post by:
G'day all, I'm trying to update a single table (containing plans for flights) with information from the same and other tables (containing info for organisations and locations). tblFlightPlans contains the txt-column 'TripSummary', which is what I'm trying to update, as well as ID numbers for the origin, destination, and plane carrier (eg, Qantas). The SQL code below successfully joins tblLocations and tblFlightPlans and updates TripSummary...
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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,...
0
10259
Oralloy
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...
0
9906
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7456
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2849
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.