w3resource

MySQL Exact Phrase Full-Text Search with Solution


Searching for Exact Phrases Using Quoted Strings

Write a MySQL query to perform a full-text search for the exact phrase "data science" in the "Content" column using boolean mode.

Solution:

-- Search for the exact phrase "data science" using BOOLEAN MODE.
-- The MATCH function is used to specify the column (Content) to search within.
-- AGAINST defines the search query and the mode (BOOLEAN MODE) for advanced search capabilities.
-- The double quotes around "data science" ensure that the exact phrase is matched, not individual words.
SELECT * 
FROM Articles
WHERE MATCH(Content) AGAINST('"data science"' IN BOOLEAN MODE);

Explanation:

  • Purpose of the Query:
    • To retrieve articles containing the exact phrase "data science".
    • Demonstrates the use of double quotes in BOOLEAN MODE for exact phrase searching.
  • Key Components:
    • '"data science"' : The phrase enclosed in double quotes indicates an exact match.
    • IN BOOLEAN MODE : Specifies that boolean operators are used.
  • Real-World Application:
    • Useful in academic and technical search engines where precise phrases are important

Notes:

  • Exact phrase searches may yield fewer results; adjust criteria as needed.
  • Ensure proper indexing for reliable performance.

For more Practice: Solve these Related Problems:

  • Write a MySQL query to perform a full-text search in BOOLEAN MODE for the exact phrase "data science" in the Content column by enclosing the phrase in double quotes.
  • Write a MySQL query to search for the exact phrase "big data analytics" in the Content column using BOOLEAN MODE with quoted strings.
  • Write a MySQL query to perform a full-text search for the exact phrase "machine learning model" in the Content column by applying double quotes in BOOLEAN MODE.
  • Write a MySQL query to search in BOOLEAN MODE for the precise phrase "predictive analytics" in the Content column, ensuring the phrase is enclosed in quotes.


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

Previous MySQL Exercise: Using Full-Text Search in a Subquery.
Next MySQL Exercise: Using Full-Text Search with a JOIN Query.

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.