
- 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
Select rows containing a string in a specific column with MATCH and AGAINST in MySQL
Let us first create a table −
mysql> create table DemoTable1833 ( Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Alter table −
Mysql> alter table DemoTable1833 ADD FULLTEXT(Name); Query OK, 0 rows affected, 1 warning (0.00 sec) Records: 0 Duplicates: 0 Warnings: 1
Insert some records in the table using insert command −
mysql> insert into DemoTable1833 values('John Doe'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1833 values('Adam Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1833 values('Chris Brown'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1833 values('John Smith'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1833;
This will produce the following output −
+-------------+ | Name | +-------------+ | John Doe | | Adam Smith | | Chris Brown | | John Smith | +-------------+ 4 rows in set (0.00 sec)
Here is the query to select rows containing a string in a specific column
mysql> select * from DemoTable1833 where MATCH(Name) AGAINST('+John Smith+') ;
This will produce the following output −
+------------+ | Name | +------------+ | John Smith | | John Doe | | Adam Smith | +------------+ 3 rows in set (0.00 sec)
- Related Articles
- Select column names containing a string in MySQL?
- Select specific rows in a range with MySQL?
- MySQL query to SELECT rows with LIKE and create new column containing the matched string?
- Find rows with a match in a pipe delimited column with MySQL
- How select specific rows in MySQL?
- MySQL query to count rows with a specific column?
- Find rows where column value ends with a specific substring in MySQL?
- Select * but ignore displaying results containing a specific character in MySQL
- MySQL query to select a specific string with special characters
- Select a specific value between two column values in MySQL?
- Fetch a specific record from a column with string values (string, numbers and special characters) in MySQL
- Fetch specific rows from a MySQL table with duplicate column values (names)?
- MySQL random rows sorted by a specific column name?
- Delete only specific rows in a table with MySQL
- How to select record except the lower value record against a specific value in MySQL?

Advertisements