1

Sorry if the question is silly but I am very noob with MYSQL and I am trying to update my table to clean and standardise the table. So I learned how to use the UPDATE command however I just want to check if there is a way to do the following:

UPDATE parse SET Stock = REPLACE(Stock, 'ETA%', 'Sold out');

Basically I want to have all the lines in my table that contain (or start with) ETA and change it to Sold out. The data is extracted from sites so Stock column has a bunch of crap like "ETA: 19-May" "ETA: in 5 days". I just want to change this all at once to "Sold out". Is there a way to do this?

I have also tried: UPDATE parse SET Stock = IF(Stock REGEXP '^ETA', 'Sold out', Stock);

but it didn't work. Any suggestion? Thanks !

2 Answers 2

2

You should add condition in where clause as shown below:

UPDATE parse SET Stock = 'Sold out' WHERE Stock LIKE '%ETA%';
Sign up to request clarification or add additional context in comments.

Comments

0

You don't even need REGEXP here:

UPDATE parse SET Stock = 'Sold out' WHERE INSTR(Stock, 'ETA') > 0;

If you wanted to use REGEXP then you could use:

UPDATE parse SET Stock = 'Sold out' WHERE Stock REGEXP 'ETA';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.