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

  • Home
  • SEARCH
  • 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 8369579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:41:06+00:00 2026-06-09T13:41:06+00:00

I am trying to do a ‘fuzzy’ search on a sql table with names

  • 0

I am trying to do a ‘fuzzy’ search on a sql table with names of people:

This is the table:

+----+------------+
| T1 | T2         |
+----+------------+
| 1  | Last,First |
| 2  | Last,First |
| 3  | Last,First |
+----+------------+

I want to get a select statement where I query T2 with the LIKE operator such that it works even when your query is “First Last”

The only way I can think of is by splitting the values and concatenating them and then searching again for the entry. Is there a better way to do 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-06-09T13:41:07+00:00Added an answer on June 9, 2026 at 1:41 pm

    Yes, if there’s a possibility you may put both last, first and first last into the database, the better way is to design your schema properly.

    If you ever find yourself trying to search on, or otherwise manipulate, parts of columns, your schema is almost certainly broken. It will almost certainly kill performance.

    The correct way is to have the table thus:

    T1  FirstName  LastName
    ==  =========  ========
     1  Pax        Diablo
     2  Bob        Smith
     3  George     Jones
    

    Then you can more efficiently split the user-entered name (once, before running the query) rather than trying to split every single name in the database.


    In the case where the database always holds last, first, it may not actually be necessary for a schema change.

    The problem you have in that case is simply one of interpreting what the user entered.

    One possibility, although it is a performance killer, is to do a like for each separate word. So, if the user entered pax diablo, your resultant query might be:

    select T1 from mytable
        where T2 like '%pax%'
          and T2 like '%diablo%'
    

    That way, you don’t care about the order so much.

    However, given my dislike of slow queries, I’d try to steer clear of that unless absolutely necessary (or your database is relatively small and likely to stay that way).

    There are all sorts of ways to speed up these sorts of queries, such as:

    • using whatever full-text search capabilities your DBMS has.
    • emulating such abilities by extracting and storing words during insert/update triggers (and removing them during delete triggers).
    • that previous case, but also ensuring extra columns used with lower-cased values of the current column (for speed).
    • telling the user they need to use the last, first form for searching.
    • trying to avoid the %something% search string as much as possible (with something%, indexes can still be used).
    • my previously mentioned “split th name into two columns” method.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to get a wildcard search to pick up on any text in org_name
Trying to find some information on this but am unable to get any results
Trying to get my 1 table row to automatically clone exactly 24 times and
Trying to get this query to work. I'm having issues with brackets I think.
Trying to get my css / C# functions to look like this: body {
trying to get my first HTML/CSS uni assignment sorted but have become a bit
Trying to get my head around, If I select a record such as WHERE
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to figure out how I can do this properly. The print_r looks like
trying to figure out why this is happening - I have an input text

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.