
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Query Results with Less Than X Characters in MySQL
You can use CHAR_LENGTH() along with the WHERE clause. Let us first create a table −
mysql> create table DemoTable -> ( -> FullName varchar(50) -> ); Query OK, 0 rows affected (1.75 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris Brown'); Query OK, 1 row affected (0.40 sec) mysql> insert into DemoTable values('David Miller'); Query OK, 1 row affected (0.91 sec) mysql> insert into DemoTable values('Robert Miller'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values('John Smith'); Query OK, 1 row affected (0.89 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------+ | FullName | +---------------+ | Chris Brown | | David Miller | | Robert Miller | | John Smith | +---------------+ 4 rows in set (0.00 sec)
Here is the query to get records that have less than X characters in MySQL −
mysql> select *from DemoTable where char_length(FullName) < 12;
This will produce the following output −
+-------------+ | FullName | +-------------+ | Chris Brown | | John Smith | +-------------+ 2 rows in set (0.00 sec)
Advertisements