Solved

Update Query from same table

Posted on 2014-07-25
8
369 Views
Last Modified: 2014-07-25
In MS Access I need to update two records(ProductID = 112,113) from   third record( ProductID  = 111) in the same table.
e.g  table tblProduct.

Product_ID            Color             Manufacture            ImportedYesNo             Product Group
      111            Black            Domestic                   No                  AA
      112                                                            
      113                                                                        
      114            White            Foreign                        Yes                  BB
      115            White            Domestic                                    No                                         BB
0
Comment
Question by:Taras
8 Comments
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 40219456
update with join looks like this in Access:
http://www.techonthenet.com/access/queries/update2.php
Or better, see the comment on 2009-09-16 from our top DB Guru:
http://www.experts-exchange.com/Database/Miscellaneous/A_1517-UPDATES-with-JOIN-for-everybody.html

So ...
Update tblProduct T1 Inner Join tblProduct T2 on T1.ProductID in (112, 113) and T2.Product_Id = 115
Set T1.Color = T2.color, T1.Manufacture=T2.manufacture, T1.ImportedYesNo=T2.ImportedYesNo, T1.ProductGroup = T2.ProductGroup

Open in new window

0
 

Author Comment

by:Taras
ID: 40219580
Sorry I did not put question properly. Values for records which need to be updated and record which is used for update are in different tables.
So table Product is the same but there are next two tables.
This is table that has value of Product ID’s which will be updated in table tblProduct.
tlbRecordsToBeUpdated(Only one filed with two records  for update)
ProductID
112
113

This is table that has the record  from table tblProduct , the record that will be used for update.
TblRecordUsedForUpdate (only one record)
Product_ID      Color             Manufacture            ImportedYesNo       Product Group
111            Black            Domestic             No                  AA
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 40219607
Whether you are joining a table to itself or to another table, the syntax is the same.  Just replace the second instance of the first table name to the name of the second table.

The larger question is what is the common field?  Surely you are not just updating two specific records.  Given that, the suggested solution won't be much help.  I don't see anything in record 111 that would link it to records 112 and 113 in the other table.
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40219631
It would be helpful to see a screen shot of the Relationships diagram (if you haven't made any links, that would be a problem).
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:Taras
ID: 40219738
Part Hartman.
There are three tables not two.
How they are related?

Table tblProduct has Product ID that is related to TblRecordUsedForUpdate .ProductID.
And it has all records in.
Table tlbRecordsToBeUpdated  has only records ProductID's  that need to be updated and those ProudutID' are in TblProduct too.

It means three tables One where All records exist.
And two other. One of those two has and always will have  only one complete record which is identical as that in tblProduct and is used for update and Second table has only values of ProductID' that has to be updated in tblProduct.
Do not if this help.
0
 

Author Comment

by:Taras
ID: 40219745
PatHartman, apologize for name misspelling.
0
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
ID: 40220106
I am still missing how the tables are used.  Are you trying to update tblProduct with data from TblRecordUsedForUpdate  using tlbRecordsToBeUpdated  to specify which records will be updated?  So in this scenario, tblRecordsToBeUpdated will contain only the productID and is used only for the purpose of controlling which records get changed.

It is really unusual to have three tables in this scenario so we need to understand the purpose of each.  If I have described the usage correctly, add all three tables to the QBE.  Draw join lines connecting ProductID between tblProduct and tblRecordsToBeUpdated and then from tblRecordsToBeUpdated to tblRecordUsedForUpdate.  Then select all the columns from tblProduct that will be updated (not the PK) and change the query type to Update.  Then in the UpdateTo cell for each column type in the name of the column from tblRecordUsedForUpdate including the table name.
0
 

Author Closing Comment

by:Taras
ID: 40220243
Thanks Pat.
Thanks for your suggestion, in broader context this table,  tblRecordsToBe updated has records that belong to a specific group. In that specific group belongs  record  in table tblRecordUsedForUpdate used for update.
You are right in first part of your answer.Table  “tblRecordsToBeUpdated”  only has role to identify  those records which will be updated in tblProucts.
You missed  one small thing but  very important, that table had just one field.
 I added another field named Link_ProductID (it has the same value as s ProductID  in tblRecordUsedForUpdate)  and  it is same for all records in table.
That field is used for connection with tblProduct, otherwise without that field your second part of answer would not be  possible.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now