- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 can we use CHAR_LENGTH() function with MySQL WHERE clause?
When CHAR_LENGTH() or CHARACTER_LENGTH() string function is used with WHERE clause, the output returns by it will depend upon the condition given in WHERE clause. For example, suppose we have a table named ‘Student’ and we want to get only those names having number of characters less than 6, then we can write 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)
Advertisements