w3resource

Basic MySQL Full-Text Search on Single Column with Solution


Basic Full-Text Search on a Single Column

Write a MySQL query to perform a basic full-text search on the "Content" column of the Articles table for the term "database".

Solution:

-- Perform a basic full-text search on the "Content" column for the term 'database'.

-- Select all columns from the Articles table where the Content column matches the search term.
SELECT * 
-- Specify the table from which to retrieve the data.
FROM Articles

-- Use the MATCH...AGAINST clause to perform a full-text search.
-- MATCH(Content) specifies the column to search, and AGAINST('database') specifies the search term.
WHERE MATCH(Content) AGAINST('database');

Explanation:

  • Purpose of the Query:
    • To retrieve articles that contain the term "database" within their content.
    • Demonstrates the basic use of MATCH...AGAINST for full-text searching.
  • Key Components:
    • MATCH(Content) : Specifies the column to search.
    • AGAINST('database') : Indicates the search term in natural language mode.
  • Real-World Application:
    • Useful in blog or news websites where users search for specific topics.

Notes:

  • Ensure the "Content" column has a full-text index.
  • This query uses natural language mode by default.

For more Practice: Solve these Related Problems:

  • Write a MySQL query to perform a full-text search on the "Content" column for the phrase "advanced indexing" while ignoring common stop words.
  • Write a MySQL query to search the "Content" column for the term "MySQL performance" and return results even if the term appears only once.
  • Write a MySQL query to perform a full-text search on the "Content" column for the phrase "database scalability" ensuring the search is case-insensitive.
  • Write a MySQL query to execute a full-text search on the "Content" column that returns results even when the search term is shorter than the minimum word length.


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous MySQL Exercise: MySQL Full-Text Search Home.
Next MySQL Exercise: Full-Text Search on Multiple Columns.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.