Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update a table with a table

Status
Not open for further replies.

thysonj

Programmer
Jul 6, 2001
240
US
I am trying to update a table with a table and cannot get it right. My two tables are below:
Code:
Products Table
PID_pk  FSC  NIN  PackageDesc
6       null null null
7       null null null
8       null null null
9       null null null
10      null null null
etc..

Package Table
ID  PID_fk  FSC  NIN  PackageDesc
1   6       9    67   blah
2   7       9    86   blah 
3   8       9    45   blah
4   9       5    45   blah  
5   10      5    23   blah   
etc...

I need to get the Package table data into the Products Table

obviously PID_pk is the foreign key referenced by PID_fk

Please help!
 
Try something like the following.

--Update Products
-- SET FSC = PAC.FSC,
-- NIN = PAC.NIN,
-- PackageDesc = PAC.PackageDesc
SELECT *
FROM Products PRO
INNER JOIN Package PAC
ON PAC.PID_pk = PRO.PID_pk

Check the select first, if it is what you require then comment out the select and try the update.

Hope this helps,

Chris Dukes
 
--Update Products
-- SET FSC = PAC.FSC,
-- NIN = PAC.NIN,
-- PackageDesc = PAC.PackageDesc
won't work...it doesn't "know" what PAC is
 
In the update portion, expand PAC to be PACKAGE. The alias is only working in the SELECT portion.

-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top