EnexoOnoma
EnexoOnoma

Reputation: 8836

Is there a faster way to write those 3 same queries?

Is there any faster query way of rewriting these queries or by combining them?

update products
set shop = '1' 
where shop LIKE '%demo%'

update products
set shop = '2' 
where shop LIKE '%car%'

update products
set shop = '3' 
where shop LIKE '%art%'

Upvotes: 2

Views: 101

Answers (2)

Cybercartel
Cybercartel

Reputation: 12592

Maybe a stored procedure: http://www.sqlinfo.net/mysql/mysql_stored_procedure_UPDATE.php

Upvotes: 0

Nicola Cossu
Nicola Cossu

Reputation: 56357

update products
set shop =
case 
when shop like '%demo%' then 1
when shop like '%car%' then 2
when shop like '%art%' then 3
else shop
end

Upvotes: 4

Related Questions