Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 647
  • Last Modified:

Advanced Update query

I have 2 tables:

Table 1
OrderID
ProductID
ItemQuantity
ItemName
ItemCost


Table 2
SessionID
ProductID
ItemQuantity

What I am trying to do is update Table1.ItemQuantity with values of Table2.ItemQuantity where their productIDs are equal.


Thanks for your help
0
zagnutts
Asked:
zagnutts
2 Solutions
 
Anthony PerkinsCommented:
Update Table1
Set ItemQuantity = Table2.ItemQuantity
From Table1
         Inner Join Table2 On Table1.ProductID = Table2.ProductID

Also, please maintain this old open question:
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20725832.html

Thanks,
Anthony
0
 
namasi_navaretnamCommented:
What  is the PK for Table1, Table2?

In the scenario illustrated below, should the ItemQuantity be updated with value 5 or 6?

Table1
Product1D ItemQuantity
===============
1             4        
2             ?

Table2
Product1D ItemQuantity
===============
1             4        
2             5
2             6

SQL you are asking for is listed below. But the update may be incorrect?

Update Table1
Set      ItemQuatity = Table2.ItemQuantity
FROM Table2
WHERE Table1.ProductId = Table2.ProductId

HTH

Namasi Navaretnam




0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now