Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6674813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:46:31+00:00 2026-05-26T03:46:31+00:00

I have a form with an input box where the user can specify their

  • 0

I have a form with an input box where the user can specify their names, the names may be two or more words, eg John Smith or John Michael Smith.

I have to write a query that returns records containing all words in the name presented. So query will return records that has the name of all those words, but may have different order.

For example, if the search string is John Michael Smith, the query should be able to return records with names like Michael John Smith, Michael Smith John, John Smith Michael or some combination of all these words there. As can be seen only return records that still has all the words in the name field, but may have different order. However, it should return results that do not contain part of the name, for example, John Michael should not be returned because it does not have Smith in there.

I tried query like this:

SELECT id, name FROM users WHERE
     name LIKE '%Michael%' &&
     name LIKE '%Smith%' &&
     name LIKE '%John%'

The same problem happens with:

SELECT * FROM users WHERE MATCH (name)
    AGAINST ('+Michael +Smith +John' IN BOOLEAN MODE);

Both queries also returns John Michael instead of records that contain all three words 🙁

I can not figure out how to write a query to the requirement so that I have. Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:46:31+00:00Added an answer on May 26, 2026 at 3:46 am

    Use a fulltext index. That’s the easiest/quickest method. Otherwise you’re stuck parseing your search string, converting

    John Michael Smith
    

    into

    SELECT ... WHERE (name LIKE '%John%') OR (name LIKE '%Michael%') OR (name LIKE '%Smith%')
    

    which very quickly gets painful to do, and VERY slow to perform, as LIKE %..% searches cannot use indexes.

    Note that Fulltext indexes are currently restricted to MyISAM tables, so if you’re on InnoDB, you’ll have to use workarounds (parallel tables in MyISAM format to hold the searchable data with triggers to keep the two copies synchronized). Apparently Fulltext for InnoDB is FINALLY in the development pipeline, but it’s not here yet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with an input box where user can specify their names,
I have an input form with two textareas allowing a user to type in
id like to have an input box that a user can enter a search
i have one form which have some input box and some select box. i
I have a form in a .html files where input/select box looks like this
I have... a dynamic populated select box several input boxes a submit button form
I have form with one input for email and two submit buttons to subscribe
I have a requirement whereby a user can specify a variable number of user-defined
I have an HTML form that a user can add an arbitrary amount of
I have a form where users can introduce google maps urls to specify the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.