![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Display specific name from a table with repeated individual FirstName and LastName using LIKE clause twice
Let us first create a table −
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(30) ); Query OK, 0 rows affected (0.70 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(StudentName) values('John Smith'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentName) values('David Miller'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentName) values('Carol Taylor'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentName) values('John Doe'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentName) values('Chris Brown'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(StudentName) values('Adam Doe'); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+---------------+ | StudentId | StudentName | +-----------+---------------+ | 1 | John Smith | | 2 | David Miller | | 3 | Carol Taylor | | 4 | John Doe | | 5 | Chris Brown | | 6 | Adam Doe | +-----------+---------------+ 6 rows in set (0.00 sec)
Here is the query to select record from table with first name “John” and last name “Doe” −
mysql> select *from DemoTable where StudentName LIKE '%John%' and StudentName LIKE '%Doe%';
This will produce the following output −
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 4 | John Doe | +-----------+-------------+ 1 row in set (0.00 sec)
Advertisements