Solved

MS access and Update/Select

Posted on 2016-11-02
5
69 Views
Last Modified: 2016-11-03
How can I do something like below in MS access, where I'm updating a record in the  equipment table based on a related record in th e same equipment table.  

update equipment set local_indicator_id = (select local_id from equipment where id = 8309)  
where equipment.id = 8265
0
Comment
Question by:HLRosenberger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 41871067
try
update equipment set local_indicator_id = (select local_id from equipment As E where E.id = 8309)  
 where equipment.id = 8265
0
 
LVL 36

Accepted Solution

by:
PatHartman earned 250 total points
ID: 41871114
Open the QBE.
Add the equipment table twice.  The second instance will be suffixed with "_1".  This is just an alias
Draw join lines between the two tables.
Add selection criteria if necessary.
Select the column you want to update.
Change the query type to Update.
In the Update To line, type the name of the column that contains the data you want in the format -
[tablename].[columnname]
0
 
LVL 30

Expert Comment

by:hnasr
ID: 41871164
Other approach: to avoid hard coding the query.

Create a table u(f, t) with entries from id to id

f          t
8265 8309
------  ------

UPDATE  equipment  inner join u on equipment .local_indicator_id=u.f
set equipment .local_indicator_id =u.t
0
 
LVL 36

Assisted Solution

by:PatHartman
PatHartman earned 250 total points
ID: 41871221
I don't think the OP actually wants to have literals in the query.  Parameters perhaps, but not literals.  However, if there is no field on which to join the two instances, then a cross reference table might be needed.
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 41872029
Thanks!
0

Featured Post

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.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

756 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