-2

I have 2 different tables in my database and can't find any reference on how to use a result to update a part of a table.

Here is my scenario

Table: MenuItems

╔════╦══════════════╦
║ id ║  Name        ║
╠════╬══════════════╬
║  1 ║ test         ║
║  2 ║ test2        ║
╚════╩══════════════╩

Table: MenuItemPrices

╔════╦══════════════╦
║ id ║  Price       ║
╠════╬══════════════╬
║  1 ║ 3.50         ║
║  2 ║ 4.50         ║
╚════╩══════════════╩

Say I want to update test2 price to 5.00, what would be the query I need?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

0
UPDATE p
SET    Price = 5.00
FROM   MenuItems i
INNER JOIN MenuItemPrice p ON i.id = p.id
WHERE  i.Name = 'test2'
Squirrel
  • 23,507
  • 4
  • 34
  • 32
0
UPDATE p
SET Price = 5.00
FROM   
    MenuItems i,
    MenuItemPrice p 
WHERE 
    i.id = p.id AND
    i.Name = 'test2'
openwonk
  • 14,023
  • 7
  • 43
  • 39