Nicholas Chappell
Nicholas Chappell

Reputation: 17

MYSQL replace a cell based on the value of another cell

Hi guys basically a friend wants to run a query that basically:

If mpn column contains hsun then replace the supplier id cell with the number 4 in a table called product

We've tried

UPDATE product SET supplier_id='4' WHERE mpn='%hsun%';

But keeps returning 0 items updated?

Upvotes: 0

Views: 180

Answers (2)

Steve
Steve

Reputation: 11963

UPDATE product SET supplier_id='4' WHERE mpn LIKE '%hsun%'; 

equal sign will try to match the exact string, where LIKE would treat % as wildcard

Upvotes: 0

Marc B
Marc B

Reputation: 360702

Try

WHERE mpn LIKE '%husn%'

instead. % and _ are plain characters with no special meaning when you're doing straight equality (=) testing. It's only when you use LIKE that they become wildcards.

Upvotes: 1

Related Questions