Thursday 30 August 2018

Merge two tables and update a WHERE attribute

I have two tables looking like this:

Games(Name, Maker, Year);
Fees(Name, ID, Price, Players);
I want to update the price of the games that has the maker 'Microsoft'.
Any help is appreciated.
I think the way is to merge the two tables where the names are equal and then update the Fees.price where Maker = Microsoft. But I'm unsure on how to do it.
I believe the answers from both @SheldonNeilson and @Gordon Linoff works, although I could only grant one checkmark.

If you want to reduce the price by 10% for all Microsoft games, then you can use:
update fees
    set price = price * 0.9
    where name in (select g.name from games g where g.maker = 'Microsoft');

Note that this is standard syntax should work in any database.

0 comments:

Post a Comment