views:

102

answers:

2

I have two tables...

table1 ( id, item, price ) values:

id | item | price
-------------
10 | book | 20  
20 | copy | 30   
30 | pen  | 10

....table2 ( id, item, price) values:

id | item | price
-------------
10 | book | 20
20 | book | 30

Now I want to:

update table1 
   set table1.Price = table2.price 
 where table1.id = table2.id
   and table1.item = table2.item.

How do I do it?

+1  A: 

something like this should do it :

update table1 
   set table1.Price = table2.price 
   FROM table1  INNER JOIN  table1.id = table2.id
   where table1.item = table2.item

NOTE: please backup your data before testing!!!!!

RageZ
It gives me error message: invalid object table1.
mrp
It gives me errorThe multi-part identifier "table1.price" could not be bound.
mrp
make sure you don't use `Table1` but `table1` MSSQL seems to be case sensitive.
RageZ
THANK YOU , PROBLEM IS SOLVED.
mrp
@mrp: glad you solved your problem.
RageZ
That won't work in Oracle.
Gary
A: 

Hi,

this will surely work.....

update table1 set table1.price=(select table2.price from table2 where table2.id=table1.id and table2.item=table1.item);

Best Regards,

Nadeem