
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to find all rows where string contains less than four characters?
Use CHAR_LENGTH() and find the count of characters in every string and then get the strings which are less than four characters. Let us first create a table −
mysql> create table DemoTable -> ( -> Name varchar(100) -> ); Query OK, 0 rows affected (1.38 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (1.60 sec) mysql> insert into DemoTable values('Carol'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (1.83 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.32 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Name | +-------+ | John | | Bob | | Carol | | David | | Sam | +-------+ 5 rows in set (0.00 sec)
Following is the query to find all rows where string contains less than four characters −
mysql> select *from DemoTable where CHAR_LENGTH(Name) < 4;
This will produce the following output −
+------+ | Name | +------+ | Bob | | Sam | +------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL query to find all rows where ID is divisible by 4?
- Query results that have less than X characters in MySQL?
- MySQL query to delete all rows older than 30 days?
- MongoDB query where all array items are less than a specified condition?
- MySQL search if more than one string contains special characters?\n
- Fetch rows where a field value is less than 5 chars in MySQL?
- MySQL Query to remove all characters after last comma in string?
- Select MySQL rows where column contains same data in more than one record?
- MySQL query to group rows by the numeric characters in a string field?
- MySQL query to select rows older than a week?
- Program to find number of unique four indices where they can generate sum less than target from four lists in python
- MySQL query to order rows with value greater than zero?
- Python program to check if a string contains all unique characters
- SELECT where row value contains string in MySQL?
- How to count all characters in all rows of a field in MySQL?

Advertisements