- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Update a column in MySQL and remove the trailing underscore values
To remove the trailing values, use TRIM() as in the below update syntax −
update yourTableName set yourColumnName=trim(trailing '_' from yourColumnName);
Let us first create a table −
mysql> create table DemoTable1521 -> ( -> StudentCode varchar(20) -> ); Query OK, 0 rows affected (1.33 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1521 values('345_'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1521 values('12345'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable1521 values('9084_'); Query OK, 1 row affected (1.29 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1521;
This will produce the following output −
+-------------+ | StudentCode | +-------------+ | 345_ | | 12345 | | 9084_ | +-------------+ 3 rows in set (0.00 sec)
Here is the query to update column in MySQL and trim −
mysql> update DemoTable1521 -> set StudentCode=trim(trailing '_' from StudentCode); Query OK, 2 rows affected (0.34 sec) Rows matched: 3 Changed: 2 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable1521;
This will produce the following output −
+-------------+ | StudentCode | +-------------+ | 345 | | 12345 | | 9084 | +-------------+ 3 rows in set (0.00 sec)
- Related Articles
- Using MySQL IN() for some column values with underscore
- Remove trailing numbers surrounded by parenthesis from a MySQL column
- Remove Trailing Zero in MySQL?
- MySQL UPDATE column names and set None values with N/A?
- Update existing column data in MySQL and remove the last string from a varchar column with strings and numbers
- How to update a column with the same values (not all) using UPDATE, SET and LIMIT in MySQL?
- How to remove everything before values starting after underscore from column values of an R data frame?
- How to remove leading and trailing whitespace in a MySQL field?
- MySQL update column to NULL for blank values
- MySQL query to remove trailing spaces
- How to modify key values in an object with JavaScript and remove the underscore?
- How to update a MySQL table by swapping two column values?
- How to remove leading and trailing whitespace from a MySQL field value?
- Python Pandas – Remove leading and trailing whitespace from more than one column
- Set particular value of column without using update and while inserting values in MySQL

Advertisements