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 586415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:06:17+00:00 2026-05-13T15:06:17+00:00

I have a user table with columns named first_name and last_name . SELECT *

  • 0

I have a user table with columns named first_name and last_name.

SELECT * 
    FROM users 
WHERE first_name LIKE '%keywords%' 
    OR last_name LIKE '%keywords%'

Using the above, if I search for “John” or for “Doe” I’ll get a hit.

But if I search for “John Doe” I will get 0 results. How can I search MySQL in a way that will match “first_name last_name” rather than just one or the other?

  • 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-13T15:06:18+00:00Added an answer on May 13, 2026 at 3:06 pm

    One solution is to split the keywords in your application, and then build the query as follows:

    -- Split "John Doe" -> "John", "Doe"
    
    SELECT * FROM users WHERE
    (
        (
             first_name LIKE '%keyword_1%' OR
             last_name LIKE '%keyword_1%'
        )
        AND
        (
             first_name LIKE '%keyword_2%' OR
             last_name LIKE '%keyword_2%'
        )
    )
    

    The above would also match “Doe Joe”, not just “Joe Doe”. This will get bigger if you are searching into more columns, as you will have to add an “AND block” for each keyword.

    In addition, this comes with a big performance cost, since such a query is unable to use indexes on first_name and last_name, if there are any. A better approach would be to use Full Text indexing.

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

Sidebar

Related Questions

Hi i have the following query/table from a local bookstore $queryadmin =SELECT last_name, first_name,
I have a table of users with three columns. Username Accepted Rejected User 1
Rails 3.1 Devise 1.4.2 I've added first_name and last_name columns to devise's User table.
Consider i have a user table and I have three columns mobilePhone , homePhone
I have a table with three columns: user varchar, status varchar , rep int
I have a table in HTML which has three columns i.e Error - User
I have a table called credit_log and the columns are user_id | amount The
I have a table called order which contains columns id , user_id , price
I have a user table in my mysql database that has a password column.
Currently I have a User table that has a toys_owned column that is an

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.