DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Updating a table from another table
Michel
Michel

Posted on • Updated on • Originally published at blog.pagesd.info

Updating a table from another table

It's the end of the year, so I'm just going to translate an old post from 2007 that I still refer to once in a while : Mise Γ  jour d'une table Γ  partir d'une autre.

To update a column in a table from the equivalent column of another table, MS Access easily accepts two table names for the UPDATE command, but not SQL Server.

Example: after updating the VAT rates in the products table, you have to copy these revisions in the invoice details table.

With Access:

UPDATE InvoiceDetails, Products
SET    InvoiceDetails.VatRate = Products.VatRate
WHERE  InvoiceDetails.Product_ID = Products.Product_ID
Enter fullscreen mode Exit fullscreen mode

With SQL Server:

UPDATE InvoiceDetails
SET    InvoiceDetails.VatRate = Products.VatRate
FROM   InvoiceDetails
INNER JOIN Products ON Products.Product_ID = InvoiceDetails.Product_ID
Enter fullscreen mode Exit fullscreen mode

With Oracle:

UPDATE InvoiceDetails
SET    InvoiceDetails.VatRate = (SELECT Products.VatRate
                                 FROM   Products
                                 WHERE  Products.Product_ID = InvoiceDetails.Product_ID)
Enter fullscreen mode Exit fullscreen mode

This post was originally published on my blog.
Cover image : dbdiagram.io.

Top comments (3)

Collapse
 
akonibrahim profile image
Akonibrahim

Did you used any tool to generate the diagram of the tables?

Collapse
 
michelc profile image
Michel

It's a screenshot of the website dbdiagram.io, a free online tool to draw ER diagrams.

Collapse
 
akonibrahim profile image
Akonibrahim

Pretty cool thank you

Build Anything...


Use any Linode offering to create something for the DEV x Linode Hackathon 2022. A variety of prizes are up for grabs, inculding $1,000 USD. πŸ‘€

β†’ Join the Hackathon <-