Reputation: 137
I want to keep first 2 characters of the column value and delete rest characters in mysql table.
+----------------+
| id | firstname |
+----------------+
| 1 | XYZUUIJ |
| 2 | ABCF |
+----------------+
Result :
+----------------+
| id | firstname |
+----------------+
| 1 | XY |
| 2 | AB |
+----------------+
Upvotes: 2
Views: 186
Reputation: 13506
You can use substring()
to do it
UPDATE TABLE1 SET firstname=SUBSTRING(firstname,1,2);
Upvotes: 4
Reputation: 50163
Use left()
:
select id, left(firstname, 2) as firstname
from table t;
I think you don't need to delete or update the table, you can use SELECT
statement with LEFT()
Upvotes: 4