473,513 Members | 8,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update queries using more than one table

In Access, if I want to update one table with information from another,
all I need to do is to create an Update query with the two tables, link
the primary keys and reference the source table(s)/column(s) with the
destination table(s)/column(s). How do I achieve the same thing in SQL?
Regards
Colin

*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '05 #1
3 7496
See Example C under UPDATE in Books Online, and also "Changing Data
Using the FROM Clause".

Simon

Jul 23 '05 #2
Did you lookup the UPDATE statement in Books Online? It has several
examples:
http://msdn.microsoft.com/library/de...ua-uz_82n9.asp

Do note the warning about the proprietary UPDATE FROM syntax:

"The results of an UPDATE statement are undefined if the statement
includes a FROM clause that is not specified in such a way that only
one value is available for each column occurrence that is updated (in
other words, if the UPDATE statement is not deterministic)."

That should be common sense but I've seen too many people get tripped
up by this issue. The problem is that this unpredictable behaviour is
silent. No error or warning is given so a serious bug could go
undetected. Check and test your code carefully. The alternative is to
use a correlated subquery:

UPDATE Table1
SET col1 =
(SELECT Table2.col1
FROM Table2
WHERE Table2.col2 = Table1.col2);

I prefer that syntax because it always seems clearer and more logical
to me, also it is standard SQL rather than a Microsoft invention and
finally it doesn't suffer from the bug-feature just described (an error
is reported if the subquery yields more than a single value per row).
Admittedly the proprietary UPDATE FROM version is more concise in some
cases and frequently the proprietary version has the advantage on
performance.

Hope this helps.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #3
Thanks Simon it worked a treat.

Regards
Colin

*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '05 #4

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

Similar topics

7
248435
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
17
4972
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
16
16975
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
6
2403
by: Jeff Kowalczyk | last post by:
I need to adapt this an update statement to a general form that will iterate over multiple orderids for a given customerinvoiceid. My first concern is a form that will work for a given orderid,...
9
4333
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
4
2272
by: HEATHER CARTER-YOUNG | last post by:
Please help. I have two databases - one I'm designing that will be our in-house data mgmt system (db1) and another that is a federally-mandated system (db2). We must submit data from db2 but don't...
3
2257
by: LP | last post by:
Hello, In the past I used SqlCommandBuilder and SqlDataAdapter .Update method to apply changes in a DataTable back to its table source in SQL Server. It worked fine when DataSet had only 1...
20
2469
by: Development - multi.art.studio | last post by:
Hello everyone, i just upgraded my old postgres-database from version 7.1 to 7.4.2. i dumped out my 7.1 database (with pg_dump from 7.1) as an sql-file with copy-commands and to one file using...
11
10273
by: Tim Hunter | last post by:
Hi I am using WinXP and Access 2003 Is it possible to store the field names of a table in an array and then loop through the array and update the table using the field names stored in the array? I...
16
3463
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
7254
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
7153
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
7373
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,...
1
7094
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...
0
7519
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...
1
5079
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...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1585
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 ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.