
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How MySQL LTRIM() and RTRIM()functions can be used with WHERE clause?
MySQL LTRIM() and RTRIM() functions can be used to eradicate the leading and trailing spaces from the values of a column in a table. These functions work well even if we apply a condition in WHERE clause.
Example
mysql> Select LTRIM(Name) from Student; +-------------+ | LTRIM(Name) | +-------------+ | Gaurav | | Aarav | | Harshit | | Gaurav | | Yashraj | +-------------+ 5 rows in set (0.13 sec)
The query above removes the leading space characters from the values of column ‘Name’.
mysql> Select RTRIM(Name) from Student; +-------------+ | RTRIM(Name) | +-------------+ | Gaurav | | Aarav | | Harshit | | Gaurav | | Yashraj | +-------------+ 5 rows in set (0.00 sec)
The query above removes the trailing space characters from the values of column ‘Name’.
mysql> Select LTRIM(Name) from Student Where Name = 'Harshit'; +-------------+ | LTRIM(Name) | +-------------+ | Harshit | +-------------+ 1 row in set (0.05 sec)
The query above removes the leading space characters from the value i.e. given in WHERE clause ‘Harshit’, of column ‘Name’.
mysql> Select RTRIM(Name) from Student Where Name = 'Gaurav'; +-------------+ | RTRIM(Name) | +-------------+ | Gaurav | | Gaurav | +-------------+ 2 rows in set (0.00 sec)
The query above removes the trailing space characters from the value i.e. given in WHERE clause ‘Gaurav’, of column ‘Name’.
- Related Questions & Answers
- How LOCATE() function can be used with MySQL WHERE clause?
- How can CONCAT() function be used with MySQL WHERE clause?
- How can CONCAT_WS() function be used with MySQL WHERE clause?
- How can MySQL REPLACE() function be used with WHERE clause?
- How can we use the output of LTRIM() and RTRIM() functions to update MySQL table?
- How can group functions be used in ORDER BY clause?
- How to use MySQL Date functions with WHERE clause?
- How Can we use MySQL DISTINCT clause with WHERE and LIMIT clause?
- How can I remove the leading and trailing spaces both at once from a string by using MySQL LTRIM() and RTRIM() functions?
- How can I remove the leading and trailing spaces both at once from a string without using MySQL LTRIM() and RTRIM() functions?
- How Groups function can be used in MySQL SELECT clause?
- How can we use MySQL INSTR() function with WHERE clause?
- How can we use FIND_IN_SET() function with MySQL WHERE clause?
- How can we use ASCII() function with MySQL WHERE clause?
- How can we use CHAR_LENGTH() function with MySQL WHERE clause?
Advertisements