The MySQL LTRIM() and RTRIM() functions can be used to eliminate leading and trailing spaces from column values in a table. These functions work fine even if we apply conditions in WHERE clause.
mysql> Select LTRIM(Name) from Student; +-------------+ | LTRIM(Name) | +-------------+ | Gaurav | | Aarav | | Harshit | | Gaurav | | Yashraj | +-------------+ 5 rows in set (0.13 sec)
The above query removes leading space characters from the value of the "Name" column.
mysql> Select RTRIM(Name) from Student; +-------------+ | RTRIM(Name) | +-------------+ | Gaurav | | Aarav | | Harshit | | Gaurav | | Yashraj | +-------------+ 5 rows in set (0.00 sec)
The above query removes trailing space characters from the value of the "Name" column.
mysql> Select LTRIM(Name) from Student Where Name = 'Harshit'; +-------------+ | LTRIM(Name) | +-------------+ | Harshit | +-------------+ 1 row in set (0.05 sec)
The above query removes leading space characters from the value i.e. the value given in the WHERE clause "Harshit" of the "Name" column.
mysql> Select RTRIM(Name) from Student Where Name = 'Gaurav'; +-------------+ | RTRIM(Name) | +-------------+ | Gaurav | | Gaurav | +-------------+ 2 rows in set (0.00 sec)
The above query removes trailing space characters from the value i.e. the value given in the WHERE clause "Gaurav" of the "Name" column.
The above is the detailed content of How are the MySQL LTRIM() and RTRIM() functions used with the WHERE clause?. For more information, please follow other related articles on the PHP Chinese website!