
- 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
In what cases, we cannot use MySQL TRIM() function?
Actually for using MySQL TRIM() function we must have to know the string which we want to trim from the original string. This becomes the major drawback of TRIM() in the cases where we want to trim the strings having different values. For example, suppose we want to get the output after trimming the last two characters from the strings but every string is having different characters at last two places.
Example
mysql> Select * from Employee; +------+----------------+------------+-----------------+ | Id | Name | Address | Department | +------+----------------+------------+-----------------+ | 100 | Raman | Delhi | IT | | 101 | Mohan | Haryana | History | | 102 | Shyam | Chandigarh | ENGLISH | | 103 | Sukhjeet Singh | Patiala | Computer Engg. | | 104 | Bimal Roy | Calcutta | Computer Engg. | +------+----------------+------------+-----------------+ 5 rows in set (0.00 sec)
As in the above table suppose I want to get the output after trimming the last two characters from Name, Address and Department Column then to get the desired output with one query by using TRIM() is not possible because the values at last two characters are not same.
Another case, when we cannot use TRIM() function, is When we want to remove the unwanted characters in the middle of the string. It is because TRIM() function only removes the unwanted leading or trailing characters from a string. For example, in the above table we cannot remove space between ‘Sukhjeet Singh’ by using TRIM() function.
- Related Articles
- Why in MySQL, we cannot use arithmetic operators like ‘=’, ‘
- What is the purpose of MySQL TRIM() function?
- How can we use MySQL SUM() function?
- What MySQL returns if we use UNIX_TIMESTAMP() function with no argument?
- Use TRIM on all records in a MySQL table?
- Why we cannot use MySQL DATE data type along with time value?
- trim() function in PHP
- How can we use MySQL function STR_TO_DATE(Column, ‘%input_format’)?
- In MySQL, how can we use FROM_UNIXTIME() function with format string?
- How can we use MySQL TRIM() to remove the whitespaces from all the rows and update table?
- How can we use MySQL SUM() function with HAVING clause?
- How can we use ASCII() function with MySQL WHERE clause?
- How can we use CHAR_LENGTH() function with MySQL WHERE clause?
- How can we use BIN() function with MySQL WHERE clause?
- How can we use FIND_IN_SET() function with MySQL WHERE clause?
