- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Search record with a specific value in MySQL using LIKE or REGEXP?
Let us first create a table −
mysql> create table DemoTable651 (Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,Value varchar(100)); Query OK, 0 rows affected (0.59 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable651(Value) values('Title'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable651(Value) values('course'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable651(Value) values('subject'); Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable651;
This will produce the following output −
+----+---------+ | Id | Value | +----+---------+ | 1 | Title | | 2 | course | | 3 | subject | +----+---------+ 3 rows in set (0.00 sec)
Following is the query to search a specific value using LIKE −
mysql> select *from DemoTable651 where Value LIKE 'course';
This will produce the following output −
+----+--------+ | Id | Value | +----+--------+ | 2 | course | +----+--------+ 1 row in set (0.00 sec)
Following is the query to search a specific value using REGEXP −
mysql> select *from DemoTable651 where Value REGEXP 'course';
This will produce the following output −
+----+--------+ | Id | Value | +----+--------+ | 2 | course | +----+--------+ 1 row in set (0.00 sec)
Advertisements