- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Query results that have 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)
- Related Articles
- MySQL query to find all rows where string contains less than four characters?
- Count sub-arrays which have elements less than or equal to X in C++
- Populating a table from query results in MySQL?
- Maximum subarray size, such that all subarrays of that size have sum less than k in C++
- MySQL query to add 0's to numbers with less than 9 digits?
- Maximum subarray size, such that all subarrays of that size have sum less than k in C++ program
- Query MongoDB for a datetime value less than NOW?
- Execute MySQL query from the terminal without printing results?
- How can you separate two liquids that have less than 25 K difference of boiling points?
- How to concatenate MySQL distinct query results into a string?
- Get a fixed number of results in descending order using a MySQL query
- How to order results of a query randomly & select random rows in MySQL?
- MongoDB query where all array items are less than a specified condition?
- How do I find the largest integer less than x in Python?
- MySQL query to split a column after specific characters?

Advertisements