Solved

Use join in update query

Posted on 2011-02-21
2
251 Views
Last Modified: 2012-05-11
I have 2 tables

One table is named training req which has 2 fileds

Shopnum and TrainingReqMet

Here is some sample data

Shopnum    TrainingReqMet
1                  Y
2                  Y



The other table is called shop master which has 3 fields
shopnum, dateopen, trainingreqmet

Here is some sample data

Shopnum    DateOpen                  TrainingReqMet
1                  12/01/2009                  Y
2                  12/21/2009                  N



Trying to write a query which will update the shop master table
 with the value of trainingreqmet value on Training Req table

Using sample data I would want shop master to look like the following after the query is run

Shopnum    DateOpen                  TrainingReqMet
1                  12/01/2009                  Y
2                  12/21/2009                  Y




(There is a one to one relationshiip between shopnumber on both tables)
0
Comment
Question by:johnnyg123
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 34945106
UPDATE ShopMaster
SET TrainingReqMet = tr.TrainingReqMet
FROM ShopMaster s INNER JOIN
    TrainingReq tr ON s.Shopnum = tr.ShopNum
0
 
LVL 8

Expert Comment

by:rushShah
ID: 34949193

UPDATE s
SET s.TrainingReqMet = tr.TrainingReqMet
FROM ShopMaster s 
INNER JOIN TrainingReq tr ON s.Shopnum = tr.ShopNum

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

757 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