
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Remove Trailing Zero in MySQL?
Use trim() function to remove trailing zeroz in MySQL. Following is the syntax −
select trim(yourColumnName)+0 As anyAliasName from yourTableName;
Let us first create a table −
mysql> create table removeTrailingZero -> ( -> Number DECIMAL(10,4) -> ); Query OK, 0 rows affected (0.83 sec)
Following is the query to insert some records in the table using insert command −
mysql> insert into removeTrailingZero values(10.789); Query OK, 1 row affected (0.19 sec) mysql> insert into removeTrailingZero values(89.90); Query OK, 1 row affected (0.18 sec) mysql> insert into removeTrailingZero values(8999.70); Query OK, 1 row affected (0.20 sec) mysql> insert into removeTrailingZero values(0.40); Query OK, 1 row affected (0.23 sec) mysql> insert into removeTrailingZero values(0.0); Query OK, 1 row affected (0.16 sec)
Following is the query to display all records from the table using select statement −
mysql> select * from removeTrailingZero;
This will produce the following output −
+-----------+ | Number | +-----------+ | 10.7890 | | 89.9000 | | 8999.7000 | | 0.4000 | | 0.0000 | +-----------+ 5 rows in set (0.00 sec)
Following is the query to remove trailing zeros −
mysql> select trim(Number)+0 As WithoutTrailingZero from removeTrailingZero;
This will produce the following output −
+---------------------+ | WithoutTrailingZero | +---------------------+ | 10.789 | | 89.9 | | 8999.7 | | 0.4 | | 0 | +---------------------+ 5 rows in set (0.00 sec
- Related Articles
- MySQL query to remove trailing spaces
- Remove trailing zeros in decimal value with changing length in MySQL?
- How to remove leading and trailing whitespace in a MySQL field?
- Update a column in MySQL and remove the trailing underscore values
- Remove trailing numbers surrounded by parenthesis from a MySQL column
- C program to find trailing zero in given factorial
- Remove Trailing Zeros from string in C++
- How to remove leading and trailing whitespace from a MySQL field value?
- Remove small trailing coefficients from a polynomial in Python
- Remove small trailing coefficients from Chebyshev polynomial in Python
- Remove small trailing coefficients from Hermite polynomial in Python
- Remove small trailing coefficients from Laguerre polynomial in Python
- Remove small trailing coefficients from Legendre polynomial in Python
- Remove small trailing coefficients from Hermite_e polynomial in Python
- How to remove all trailing whitespace of string in Python?

Advertisements