

- 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
MySQL query to conduct a basic search for a specific last name in a column
You can use LIKE operator to conduct a basic search for last name. Let us first create a table: −
mysql> create table DemoTable -> ( -> CustomerName varchar(100), -> CustomerAge int -> ); Query OK, 0 rows affected (0.77 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John Doe',34); Query OK, 1 row affected (1.32 sec) mysql> insert into DemoTable values('David Miller',24); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Bob Doe',27); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Carol Taylor',29); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+--------------+-------------+ | CustomerName | CustomerAge | +--------------+-------------+ | John Doe | 34 | | David Miller | 24 | | Bob Doe | 27 | | Carol Taylor | 29 | +--------------+-------------+ 4 rows in set (0.00 sec)
Following is the query to search for last name from a column −
mysql> select *from DemoTable where CustomerName LIKE '%Doe%';
Output
This will produce the following output −
+--------------+-------------+ | CustomerName | CustomerAge | +--------------+-------------+ | John Doe | 34 | | Bob Doe | 27 | +--------------+-------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- MySQL query to search within the last 5 characters in a column?
- MySQL query to display columns name first name, last name as full name in a single column?
- Fetch a specific column value (name) in MySQL
- Add a column count in a MySQL query on the basis of last name records?
- How to search a MySQL table for a specific string?
- MongoDB Query to search for records only in a specific hour?
- MySQL query to split a column after specific characters?
- MySQL query to count rows with a specific column?
- MySQL query to select everything to left of last space in a column with name records
- Get multiple count in a single MySQL query for specific column values
- MySQL random rows sorted by a specific column name?
- How to find tables with a specific column name in MySQL?
- Search for specific characters within a string with MySQL?
- Find records with a specific last digit in column with MySQL
- Search for a string within text column in MySQL?
Advertisements