
- 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
Is there a way to select a value which matches partially in MySQL?
To match partially, use LIKE operator. Let us first create a table −
mysql> create table DemoTable806( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100), StudentSubject varchar(100) ); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable806(StudentName,StudentSubject) values('Chris','Java in Depth With Data Structure'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable806(StudentName,StudentSubject) values('Robert','Introduction to MySQL'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable806(StudentName,StudentSubject) values('Bob','C++ in Depth With Data Structure And Algorithm'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable806(StudentName,StudentSubject) values('Adam','Introduction to MongoDB'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable806;
This will produce the following output −
+-----------+-------------+------------------------------------------------+ | StudentId | StudentName | StudentSubject | +-----------+-------------+------------------------------------------------+ | 1 | Chris | Java in Depth With Data Structure | | 2 | Robert | Introduction to MySQL | | 3 | Bob | C++ in Depth With Data Structure And Algorithm | | 4 | Adam | Introduction to MongoDB | +-----------+-------------+------------------------------------------------+ 4 rows in set (0.00 sec)
Following is the query to select a value which matches partially −
mysql> select *from DemoTable806 where StudentSubject LIKE '%Depth%';
This will produce the following output −
+-----------+-------------+------------------------------------------------+ | StudentId | StudentName | StudentSubject | +-----------+-------------+------------------------------------------------+ | 1 | Chris | Java in Depth With Data Structure | | 3 | Bob | C++ in Depth With Data Structure And Algorithm | +-----------+-------------+------------------------------------------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- Is there a way to retrieve the minimum value of fields in MySQL?
- Is there any way to use values from a JSON object in a MySQL Select statement?
- Is there a way to know your current username in MySQL?
- In MySQL, is there a way to turn column records into a list?
- Is there an easy way to rename a table in a MySQL procedure?
- Is there a way to make a list from a MySQL table in Java?
- Which is the fastest way to get a column's maximum value in MySQL?
- Is there a way to list collections in MongoDB?
- Is there a way to subtract number of days from a date in MySQL?
- Is there a way in MySQL to reverse a boolean field with a single query?
- Is there any way to check if there is a null value in an object or array in JavaScript?
- Is there a way to name columns in an INSERT statement in MySQL?
- Is there a default ORDER BY value in MySQL?
- Is there a way to create a MySQL “alias” while creating a VIEW?
- Which PHP function is used to select a MySQL database?
Advertisements