- 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 to implement HAVING LENGTH(field) in MySQL?
Let us first create a table −
mysql> create table DemoTable ( Title text ); Query OK, 0 rows affected (0.39 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Introduction to MySQL'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Introduction to Java'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('Introduction to SQL'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Introduction to Python'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Introduction to SQL'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('Introduction to Java'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------------------+ | Title | +------------------------+ | Introduction to MySQL | | Introduction to Java | | Introduction to SQL | | Introduction to Python | | Introduction to SQL | | Introduction to Java | +------------------------+ 6 rows in set (0.00 sec)
Following is the query to implement HAVING LENGTH(field) in MySQL −
mysql> select *from DemoTable group by length(Title) having length(Title) < 21;
This will produce the following output −
+----------------------+ | Title | +----------------------+ | Introduction to SQL | | Introduction to Java | +----------------------+ 2 rows in set (0.00 sec)
Advertisements