Solved

Advanced Update query

Posted on 2003-10-23
2
643 Views
Last Modified: 2012-06-27
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
Comment
Question by:zagnutts
[X]
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
2 Comments
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 125 total points
ID: 9611545
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
 
LVL 15

Accepted Solution

by:
namasi_navaretnam earned 125 total points
ID: 9611570
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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.

729 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