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
Solved

Join 3 tables for an Update

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

839 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