Solved

Join 3 tables for an Update

Posted on 2012-03-25
4
407 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

896 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

11 Experts available now in Live!

Get 1:1 Help Now