Select*fromStudent;+------+-- -------+----------+-----------+|Id |Name |Address|Su"/> Select*fromStudent;+------+-- -------+----------+-----------+|Id |Name |Address|Su">
When the CHAR_LENGTH() or CHARACTER_LENGTH() string function is used with a WHERE clause, the output it returns will depend on the conditions given in the WHERE clause. For example, let's say we have a table called "Student" and we want to get only those names with less than 6 characters, then we can write the following query -
mysql> Select * from Student; +------+---------+---------+-----------+ | Id | Name | Address | Subject | +------+---------+---------+-----------+ | 1 | Gaurav | Delhi | Computers | | 2 | Aarav | Mumbai | History | | 15 | Harshit | Delhi | Commerce | | 20 | Gaurav | Jaipur | Computers | +------+---------+---------+-----------+ 4 rows in set (0.10 sec) mysql> Select Name, CHAR_LENGTH(Name) from student WHERE CHAR_LENGTH(Name)<6; +-------+-------------------+ | Name | CHAR_LENGTH(Name) | +-------+-------------------+ | Aarav | 5 | +-------+-------------------+ 1 row in set (0.00 sec)
The above is the detailed content of How can we use CHAR_LENGTH() function with MySQL WHERE clause?. For more information, please follow other related articles on the PHP Chinese website!