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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:15:07+00:00 2026-05-13T00:15:07+00:00

I need to use the LIKE keyword or some other similar operator for this

  • 0

I need to use the LIKE keyword or some other similar operator for this purpose:

In the database, the name and surname is stored as one column and it’s in the order surname name (e.g. “Doe John”).

I have a search bar with lets you enter your name and surname. When I am going to search, I require that if you enter name surname instead of surname name (e.g. if you enter “John Doe”), I still want the same results to show up as if you had written surname name.

How can I achieve this?

  • 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-13T00:15:07+00:00Added an answer on May 13, 2026 at 12:15 am

    If your table is MyISAM, you can create a FULLTEXT index on both fields:

    CREATE FULLTEXT INDEX ON mytable (name, surname)
    

    and issue this query:

    SELECT  *
    FROM    mytable
    WHERE   MATCH(name, surname) AGAINST ('+John +Doe' IN BOOLEAN MODE)
    

    This will return both John Doe and Doe John.

    On a MyISAM table this query will work even without creating the index, however, in this case it will be much more slow.

    Update:

    This will work even if you have name and surname in a single field:

    CREATE TABLE t_name (id INT NOT NULL PRIMARY KEY, name VARCHAR(200) NOT NULL) ENGINE=MyISAM;
    
    INSERT
    INTO    t_name
    VALUES
    (1, 'John Doe'),
    (2, 'Doe John');
    
    SELECT  *
    FROM    t_name
    WHERE   MATCH(name) AGAINST ('+John +Doe' IN BOOLEAN MODE);
    
    1, 'John Doe'
    2, 'Doe John'
    

    Update 2:

    On an InnoDB table, you can use regular expressions:

    SELECT  *
    FROM    t_name
    WHERE   name RLIKE '[[:<:]]John[[:>:]]'
            AND name RLIKE '[[:<:]]Doe[[:>:]]'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have code with nested objects like this do I need to use
I need to use something like get_or_create() but the problem is that I have
I need to use method like: DoSomething<(T)>(); But i don't know which Type i
I have the need to use a Stack-like data structure for a program that
So I need to use the webservices of x.com something like https://x.com:1443/services/servicex?wsdl and I
I would like to use complex numbers as defined in C99, but I need
I am need to parse a pdf file. I would like to use objective-c
I need to build a feature like most of the banks use. Where.. if
I need an XML parser like SimpleXML, to use in commercial apps. I think
I need use this method with three distinct classes: Orders, Customers, Suppliers public void

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.