Solved

Join 3 tables for an Update

Posted on 2012-03-25
4
412 Views
Last Modified: 2012-03-25
I have 3 tables.
I want update 2 fields in the Nop_Product table with data from the TempOne table,
based on the SKU field matching in the Nop_ProductVariant table.

(Brand, MetaTitle2, and SKU in TempOne table)

UPDATE Nop_Product
SET  SEName2 = Brand, MetaTitle2 = Category

But the Nop_ProductVariant table has the SKU field that matches the
SKU field in the TempOne table :


WHERE Nop_Product.[ProductId] IN
(SELECT Nop_ProductVariant.ProductId FROM Nop_ProductVariant

then join the SKU from TempOne table here ???

How do I do this? thanks
0
Comment
Question by:MikeMCSD
4 Comments
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37763520
you can use something like

UPDATE
    Table
SET
    Table1.col1 = other_table.col1,
    Table1.col2 = other_table.col2
FROM
    Table1
INNER JOIN
    other_table
ON
    Table1.id = other_table.id
0
 
LVL 13

Expert Comment

by:Ashok
ID: 37763711
UPDATE Nop_Product AS A
INNER JOIN TempOne AS B ON A.F1=B.F1
JOIN Nop_ProductVariant C ON B.title_id = C.title_id
  SET A.F1 = 1, A.F2 = 2
WHERE C.SKU =101222
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 37763855
Somehting like this perhaps:
UPDATE  n
SET     SEName2 = t.Brand,
        MetaTitle2 = Category		-- Not sure what table Category belongs to.
FROM    Nop_Product n
        INNER JOIN Nop_ProductVariant v ON n.ProductID = v.ProductID
        INNER JOIN TempOne t ON v.SKU = t.SKU

Open in new window

0
 
LVL 16

Author Closing Comment

by:MikeMCSD
ID: 37763902
nicely done ac,  . .  . thanks
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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…

680 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