Reputation: 741
Let's say we have the table PEOPLE like
id | name | extracted
-----------------------------------------
1 | Roger |
-----------------------------------------
2 | Anthony |
-----------------------------------------
3 | Maria |
-----------------------------------------
We use
SELECT SUBSTRING(name, 1, 3) FROM people.name WHERE name like '%thon%'
It will find "Anthony" and extract 3 first chars - so result is : Ant
How to put this result against same id so the table looks like
id | name | extracted
-----------------------------------------
1 | Roger |
-----------------------------------------
2 | Anthony | Ant
-----------------------------------------
3 | Maria |
-----------------------------------------
Upvotes: 0
Views: 1499
Reputation: 57042
Try
UPDATE people SET extracted = LEFT(`name`,3) WHERE `name` like '%thon%'
Upvotes: 2