

- 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
Select query with regular expression in MySQL
Let us first create a table −
mysql> create table DemoTable1573 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentCode varchar(20) -> ); Query OK, 0 rows affected (0.63 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1573(StudentCode) values('STU_774'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1573(StudentCode) values('909_Sam'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1573(StudentCode) values('3_Carol_455'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1573(StudentCode) values('David_903'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1573;
This will produce the following output −
+-----------+-------------+ | StudentId | StudentCode | +-----------+-------------+ | 1 | STU_774 | | 2 | 909_Sam | | 3 | 3_Carol_455 | | 4 | David_903 | +-----------+-------------+ 4 rows in set (0.00 sec)
Here is the query to implement select query with regular expression −
mysql> select * from DemoTable1573 where StudentCode regexp '\land[0-9]';
This will produce the following output −
+-----------+-------------+ | StudentId | StudentCode | +-----------+-------------+ | 2 | 909_Sam | | 3 | 3_Carol_455 | +-----------+-------------+ 2 rows in set (0.14 sec)
- Related Questions & Answers
- Select all email addresses beginning with 5 numeric characters (regular expression) in MySQL
- MySQL select query with multiple WHERE?
- Insert with a Select query in MySQL
- Regular Expression in C# with Examples
- Regular Expression in Python with Examples?
- Text search in MongoDB with Regular Expression
- Explain JavaScript Regular Expression modifiers with examples
- MySQL query to select records with a particular date?
- MySQL select query to fetch data with null value?
- MySQL SELECT from two tables with a single query
- How to order and select query with conditions in MySQL?
- How to query an Array[String] for a Regular Expression match?
- Regular Expression "[^...]" sub expression in Java
- Select the table name as a column in a UNION select query with MySQL?
- Regular Expression Examples in Python
Advertisements