473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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=employee.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 18016
gi*******************@yahoo.com 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=employee.login)
MERGE INTO employee
USING z.employee as z
ON z.login=employee.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.com"
<gi*******************@yahoo.comwrote:
>update employee set z_emp_id =
(select z.emp_id from z.employee z where z.login=employee.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
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...
3
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...
9
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...
5
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),...
5
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...
2
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...
5
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...
5
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...
11
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...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...

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.