HShbib
HShbib

Reputation: 1841

SQL: Update table where column = Multiple Values

I created an SQL query which updates a table column where another column = value

CODE:

Update Products Set ProductName = 'Shoes' WHERE ProductID = (1,2,3,4,5,6,7,8)

The problem is with the ProductID. How can I make it update the column with those ID's ?

Regards.

Upvotes: 4

Views: 18600

Answers (3)

cmutt78
cmutt78

Reputation: 859

Both answers above are perfectly correct however if there are a list of values in a table you want to use in your IN statement you can use a SELECT statement

...WHERE name IN (select name from listofnames where lastname like 'C%')

I find this to be more of use in a dynamic environment but thought it worth a mention.

Upvotes: 0

Vilx-
Vilx-

Reputation: 106970

You just use "IN":

Update Products Set ProductName = 'Shoes' WHERE ProductID in (1,2,3,4,5,6,7,8)

Upvotes: 4

Mitch Wheat
Mitch Wheat

Reputation: 300719

Replace ProductID = with ProductID IN

Update Products 
Set ProductName = 'Shoes' 
WHERE ProductID IN (1,2,3,4,5,6,7,8) 

Upvotes: 18

Related Questions