
- 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
How to use MySQL LIKE to create a search system and display results on the basis of keyword?
To display results on the basis of keyword, use the LIKE operator as in the following syntax −
select *from yourTableName where yourColumnName LIKE '%yourValue%';
Let us first create a table −
mysql> create table DemoTable812(Comments text); Query OK, 0 rows affected (0.61 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable812 values('Good Looking'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable812 values('Awesome'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable812 values('Looking Gorgeous'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable812 values('Good Luck'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable812 values('Have a nice day'); Query OK, 1 row affected (0.21 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable812;
This will produce the following output −
+------------------+ | Comments | +------------------+ | Good Looking | | Awesome | | Looking Gorgeous | | Good Luck | | Have a nice day | +------------------+ 5 rows in set (0.00 sec)
Following is the query to use MySQL LIKE to create a search system and display results on the basis of keyword −
mysql> select *from DemoTable812 where Comments LIKE '%Look%';
This will produce the following output −
+------------------+ | Comments | +------------------+ | Good Looking | | Looking Gorgeous | +------------------+ 2 rows in set (0.00 sec)
- Related Articles
- Use MySQL LIKE and NOT LIKE to display similar results?
- How to Use Search Intent for Keyword Research that Gets Results?
- How to implement a Keyword Search in MySQL?
- Search records on the basis of date in MySQL?
- How to use MySQL LIKE query to search a column value with % in it?
- How to create rss feeds for google search results
- How to display the day name on the basis of Date of Birth records in MySQL?
- List View Search list on typing with filter like keyword search using jQuery?
- How to output MySQL query results in CSV format and display it on the screen, not a file?
- How to make MySQL display results in a single line?
- MySQL query to display records on the basis of conditions IS NULL OR !=1;?
- Display records on the basis of key-value pairs in MySQL
- Sort search results based on substring position in MySQL
- How to Display System Variables of MySQL Server?
- How to use quotes correctly while using LIKE with search variable in MySQL in Java?

Advertisements