Update table based on Join

Hi

I have table A with colums ID and Product. I have table B with ID (same as table A) and revenue of product.

I need to update the field Product of table A with the revenue of table B.

I'm confuse with the update joining both tables. I tried this, but obviously has an error:

Update A set Product=B.Revenue where A.ID=B.ID

Can you please help?

thanks,

Ezequiel

September 7th, 2015 1:44pm

Why would you update Product column with the Revenue? This makes very little sense.

Please post your tables structures, some data (as insert statements) and desired output.

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 2:01pm

Hi,

Please try below SQL script;

UPDATE A SET Product = B.Revenue
FROM B INNER JOIN A ON B.ID = A.ID 

September 7th, 2015 2:04pm

Great! it worked! thanks
Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 2:23pm

>> I have table A with column ID and Product. I have table B with ID (same as table A) and revenue of product. <<

Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. 

There is no such crap as a generic id in RDBMS. It has to be the identifier of something in particular. This is called The Law of Identity in logic. 

>> I need to update the field [sic] Product of table A with the revenue of table B. <<

Columns are not anything like fields! The data element name product is wrong. It had to be product_<something> by the ISO-11179 rules. 

>> I'm confused .. << 

Yes, you are VERY confused :) Is the magical id actually a product identifier like UPC, EAN, or GTIN? 

I will guess this is a MERGE problem. If you had followed forum rules and been polite, we could help you. But yhou have to post something that makes sense. 
September 7th, 2015 5:17pm

Hi,

Please try below SQL script;

UPDATE A SET Product = B.Revenue
FROM B INNER JOIN A ON B.ID = A.ID 

It is old Sybase proprietary syntax. It is also unpredictable. Google it.

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 5:20pm

Hi,

Please try below SQL script;

UPDATE A SET Product = B.Revenue
FROM B INNER JOIN A ON B.ID = A.ID 

It is old Sybase proprietary syntax. It is also unpredictable. Google it.

September 7th, 2015 11:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics