
- 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 select all fields beginning with a given number with next character a letter?
You can use REGEXP for this. Let us first create a table −
mysql> create table DemoTable ( Value text ); Query OK, 0 rows affected (1.28 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values('645st'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values('765stp'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('665tcp'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('606cpp'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+--------+ | Value | +--------+ | 645st | | 765stp | | 665tcp | | 606cpp | +--------+ 4 rows in set (0.00 sec)
Following is the query to select all fields beginning with a given number with the next character a letter −
mysql> select *from DemoTable WHERE Value REGEXP '^6[[:alnum:]]';
This will produce the following output −
+--------+ | Value | +--------+ | 645st | | 665tcp | | 606cpp | +--------+ 3 rows in set (0.01 sec)
- Related Articles
- MySQL query to display all the fields that contain a capital letter?
- MySQL query to select column values ending with certain character/number?
- Find all the names beginning with the letter 'a' or ‘b’ or ‘c’ using MySQL query?
- MySQL query to select records beginning from a specific id
- Query MongoDB with “like” implementation on name and email field beginning with a specific letter?
- Select particular type of columns beginning with a certain letter and concatenate the names
- Insert with a Select query in MySQL
- MySQL query to select records with a particular date?
- Select all email addresses beginning with 5 numeric characters (regular expression) in MySQL
- Query in MySQL for string fields with a specific length?
- Get the names beginning with a particular character using LIKE in MySQL
- How to select records beginning with certain numbers in MySQL?
- Find the records with % character in a LIKE query with MySQL
- MySQL query to select a record with two exact values?
- MySQL query to select a specific string with special characters

Advertisements