Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 582
HShbib Avatar asked Nov 30 '22 08:11

HShbib


2 Answers

Replace ProductID = with ProductID IN

Update Products 
Set ProductName = 'Shoes' 
WHERE ProductID IN (1,2,3,4,5,6,7,8) 
like image 116
Mitch Wheat Avatar answered Dec 02 '22 21:12

Mitch Wheat


You just use "IN":

Update Products Set ProductName = 'Shoes' WHERE ProductID in (1,2,3,4,5,6,7,8)
like image 41
Vilx- Avatar answered Dec 02 '22 21:12

Vilx-