473,802 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can an update query set values selected from another table?

I know I can use Inner Joins in an Update query like this:

UPDATE DISTINCTROW tblA INNER JOIN qryA ON tblA.SomeID = qryA.SomeID SET
Flag = 0
WHERE (Flag = -1);

But I am specifying the new value to overwrite the old value, and just using
the join to narrow the set. If I don't know the new value and need to
select it from another unrelated table with no unique ID, can I still use an
update query?

In pseudo code it might look like this:

UPDATE tblSomeData SET [MyDate] = (SELECT [MyDate] FROM tblNewDates);

How else would I update an entire table with values from another unrelated
table?

Thanks in advance.
Nov 13 '05 #1
3 2625
are you trying to update tblSomeData with a *single* value, or with
values that may vary? It looks like you're trying to update using
multiple values, but I can't be sure. In that case, you'd need an
inner join somewhere in your WHERE clause of the update query, which is
missing.

Nov 13 '05 #2
deko wrote:
I know I can use Inner Joins in an Update query like this:

UPDATE DISTINCTROW tblA INNER JOIN qryA ON tblA.SomeID = qryA.SomeID SET
Flag = 0
WHERE (Flag = -1);

But I am specifying the new value to overwrite the old value, and just using
the join to narrow the set. If I don't know the new value and need to
select it from another unrelated table with no unique ID, can I still use an
update query?

In pseudo code it might look like this:

UPDATE tblSomeData SET [MyDate] = (SELECT [MyDate] FROM tblNewDates);


That will work if tblNewDates has one record, if not you must be more
selective in the subquery, or you can use DLookup() (or tLookup
http://easyweb.easynet.co.uk/~trevor.../baslookup.zip) function
in place of the subquery.

--
This sig left intentionally blank
Nov 13 '05 #3
> > I know I can use Inner Joins in an Update query like this:

UPDATE DISTINCTROW tblA INNER JOIN qryA ON tblA.SomeID = qryA.SomeID SET
Flag = 0
WHERE (Flag = -1);

But I am specifying the new value to overwrite the old value, and just using the join to narrow the set. If I don't know the new value and need to
select it from another unrelated table with no unique ID, can I still use an update query?

In pseudo code it might look like this:

UPDATE tblSomeData SET [MyDate] = (SELECT [MyDate] FROM tblNewDates);


That will work if tblNewDates has one record, if not you must be more
selective in the subquery, or you can use DLookup() (or tLookup
http://easyweb.easynet.co.uk/~trevor.../baslookup.zip) function
in place of the subquery.


Thanks for the code. In a generic sense, then, the answer to my question
is:

UPDATE tblSomeData SET [MyDate] = Function(parame ter);

where the function interates over the new vaules.
Nov 13 '05 #4

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

Similar topics

3
3273
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old scripts working on a new server with the most recent version of PHP. I've pretty much taken care of all the various errors that were popping up. Most only pointed out out non-fatal undefined or assumed variables. I've been able to cure most of...
1
6621
by: Jim Geissman | last post by:
Help, please. I am trying to update a table with this structre: CREATE TABLE Queue (PropID int, EffDate smalldatetime, TxnAmt int) INSERT Queue (PropID) SELECT 1 INSERT Queue (PropID) SELECT 2 INSERT Queue (PropID) SELECT 3
7
4103
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
4
79488
by: gooday | last post by:
Table test2 has multiple amounts for each account, I would like to sum the amounts for the same account and use the result to update the variable 'tot_amount' in table test1. But SQL does not allow me to use sum function in update. Is there any other way to do this? Thanks. update test1 set tot_amount=sum(b.amount) from test1 as a join test2 as b on a.acc_no=b.acc_no
16
17024
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 must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
2
8542
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An example of what I'm trying to do is below: update (tbl_ind_mananas LEFT JOIN (select count(*) as count, (dubicacion || zona || manzana) as cod_manzana from tbl_censo_poblacion_1993 group by dubicacion, zona, manzana) tbl1 on relacion = cod_manzana) as...
6
4389
by: Eugene | last post by:
Summary: ---------- Updates against UNION ALL view does't do branch elimination, but rather reads all the branches (partitions). The case scenario(DB2 V8.1.4a ESE, AIX 5.2): -------------------------------------------- The UNION ALL view (tv) was built on the following three sample tables (t1,t2,t3)
13
2462
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever works best) to display a dropdown menu of fields populated from table tblInvoiceData. This control also includes a textbox which the user can input a value. These two columns are side by side and not in a vertical layout. The user then clicks on...
3
1609
by: DavidPr | last post by:
I've wrestled with this code all day and I just can't figure out what the problem is. I have this same code on the add_job.php page and the edit_job.php page and neither one is enter in the correct information into the database. But first here's a synopsis of what happens up to this point: The registration script adds users to the users table and a row in that table is named stateid. The information that goes into this stateid row is...
0
9699
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
9562
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
10304
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10063
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...
0
5494
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...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
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
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
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.