
- 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
Implement SELECT LIKE and CHAR_LENGTH() in a single MySQL query
Let us first create a table −
mysql> create table DemoTable -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.49 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris Brown'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Adam Smith'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('John Smith'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Carol Smith'); 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 −
+-------------+ | Name | +-------------+ | Chris Brown | | Adam Smith | | John Smith | | Carol Smith | +-------------+ 4 rows in set (0.00 sec)
Following is the query to implement SELECT LIKE and CHAR_LENGTH −
mysql> select * from DemoTable -> where Name LIKE '%Smith%' -> and char_length(Name) < 11;
This will produce the following output −
+------------+ | Name | +------------+ | Adam Smith | | John Smith | +------------+ 2 rows in set (0.00 sec)
- Related Articles
- Implement multiple LIKE operators in a single MySQL query
- Can we implement 'LIKE' and ‘IN’ in a single MySQL query?
- MySQL UNION SELECT and IN clause in a single query
- Implement multiple COUNT() in a single MySQL query
- MySQL select and insert in two tables with a single query
- Implement MySQL LIMIT and OFFSET in a single query stating its difference
- MySQL SELECT from two tables with a single query
- Use LIKE % to fetch multiple values in a single MySQL query
- A single MySQL select query on two tables is possible?
- Combine columns before matching it with LIKE in a single query in MySQL?
- A single MySQL query to select value from first table and insert in the second?
- Wrap around to first value and implement MySQL ORDER BY ASC and DESC in a single query
- Copy values of one column to another using INSERT and SELECT in a single MySQL query
- Display substrings of different length with a single MySQL query and combine the result
- Query MySQL with unicode char code?

Advertisements