

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Fetch rows where a field value is less than 5 chars in MySQL?
<p>To fetch rows where a field value is less than 5 chars, you need to use LENGTH() function. The syntax is as follows −</p><pre class="prettyprint notranslate">SELECT *FROM yourTableName WHERE LENGTH(yourColumnName) < 5;</pre><p>To understand the above syntax, let us create a table. The query to create a table is as follows −</p><pre class="prettyprint notranslate">mysql> create table fieldLessThan5Chars -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> yourZipCode varchar(10) -> ); Query OK, 0 rows affected (0.52 sec)</pre><p>Now you can insert some records in the table using insert command. The query is as follows −</p><pre class="prettyprint notranslate">mysql> insert into fieldLessThan5Chars(yourZipCode) values('35801'); Query OK, 1 row affected (0.10 sec) mysql> insert into fieldLessThan5Chars(yourZipCode) values('3580'); Query OK, 1 row affected (0.20 sec) mysql> insert into fieldLessThan5Chars(yourZipCode) values('90001'); Query OK, 1 row affected (0.40 sec) mysql> insert into fieldLessThan5Chars(yourZipCode) values('100'); Query OK, 1 row affected (0.20 sec) mysql> insert into fieldLessThan5Chars(yourZipCode) values('10'); Query OK, 1 row affected (0.17 sec) mysql> insert into fieldLessThan5Chars(yourZipCode) values('0'); Query OK, 1 row affected (0.15 sec) mysql> insert into fieldLessThan5Chars(yourZipCode) values('90209'); Query OK, 1 row affected (0.11 sec) mysql> insert into fieldLessThan5Chars(yourZipCode) values('33124'); Query OK, 1 row affected (0.20 sec)</pre><p>Display all records from the table using select statement. The query is as follows −</p><pre class="prettyprint notranslate">mysql> select *from fieldLessThan5Chars;</pre><p>The following is the output −</p><pre class="result notranslate">+----+-------------+ | Id | yourZipCode | +----+-------------+ | 1 | 35801 | | 2 | 3580 | | 3 | 90001 | | 4 | 100 | | 5 | 10 | | 6 | 0 | | 7 | 90209 | | 8 | 33124 | +----+-------------+ 8 rows in set (0.00 sec)</pre><h2>Example</h2><p>Here is the query to fetch all rows where a field value is less than 5 characters −</p><pre class="prettyprint notranslate">mysql> select *from fieldLessThan5Chars where length(yourZipCode) < 5;</pre><h2>Output</h2><pre class="result notranslate">+----+-------------+ | Id | yourZipCode | +----+-------------+ | 2 | 3580 | | 4 | 100 | | 5 | 10 | | 6 | 0 | +----+-------------+ 4 rows in set (0.00 sec)</pre>
- Related Questions & Answers
- Fetch rows where first character is not alphanumeric in MySQL?
- MySQL query to find all rows where string contains less than four characters?
- Deleting all rows older than 5 days in MySQL
- Delete records where timestamp older than 5 minutes in MySQL?
- Mask an array where less than or equal to a given value in Numpy
- MySQL Select where value exists more than once
- How to check whether a column value is less than or greater than a certain value in R?
- MySQL: selecting rows where a column is null?
- Check if any value in an R vector is greater than or less than a certain value.
- Match MongoDB documents with field value greater than a specific number and fetch them?
- Return element-wise True where signbit is set (less than zero) in Numpy
- Query MongoDB for a datetime value less than NOW?
- How can I find all columns where the column name length is greater than 5 in MySQL?
- Mask array elements less than a given value in Numpy
- How to select data in MySQL where a field has a minimum value?
Advertisements