
- 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
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)
- Related Articles
- MongoDB query to find documents with specific FirstName and LastName
- Using LIKE clause twice in a MySQL query
- Display specific table names with MySQL LIKE Operator
- Delete a specific record from a MySQL table by using AND in WHERE clause
- MongoDB query to find on field combination of FirstName and LastName?
- MySQL query to display records from a table filtered using LIKE with multiple words?
- Query MongoDB with “like” implementation on name and email field beginning with a specific letter?
- How to escape parentheses in MySQL REGEXP clause and display only specific values with parentheses?
- Select rows from a MySQL table and display using IN()
- How to write PHP script by using LIKE clause inside it to match the data from MySQL table?
- Change the column name from StudentName to FirstName in MySQL?
- How to display MySQL Table Name with columns?
- Create a dynamic table name from current year in MySQL like 2019
- Update the records in a table with a specific year fetched from date format like '10/12/2010'?
- MongoDB query to display documents with a specific name irrespective of case

Advertisements