How can I update Crate IDs of List of Fruits in si

2019-02-25 16:39发布

问题:

In reference to my question,

how can i update SQL table logic

I want a query which will do something like this,

I my last question was confusing hence I am asking a different question.

How can I update Crate IDs of List of Fruits in single SQL query in c#

FruitID and CrateID are foriegn keys and will always in other tables.

回答1:

Try using IN:

UPDATE FRUITS
SET CRATE = 'CRATE 7'
WHERE FRUITID IN (1, 2, 3)

Or

UPDATE FRUITS
SET CRATE = 'CRATE 7'
WHERE FRUITName IN ('Mango1', 'Mango2', 'Apple 6')

You can also use LIKE to match Mango and Orange however this may update the incorrect results (Say you want Orange 199 to be updated to Crate 7 but want Orange 198 to be Crate 6)