
- 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
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 Questions & Answers
- 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
- MySQL query to count rows with a specific column?
- How to match a regular expression against a string?
- How select specific rows in MySQL?
- Select * but ignore displaying results containing a specific character in MySQL
- Find rows where column value ends with a specific substring in MySQL?
- MySQL query to select a specific string with special characters
- Select a specific value between two column values in MySQL?
- MySQL random rows sorted by a specific column name?
- How to select record except the lower value record against a specific value 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)?
Advertisements