Search code examples
mysqlsqladvanced-search

MySQL "Advanced Where" Query


I would like to know is there any possible way, whereby MySQL query can dynamically search whatever is there in the WHERE clause.

For example if the query is

Select * 
from table 
where item = 'Dell Optiplex 390'

It should search for rows having:

Dell Optiplex 390

Dell Desktop Optiplex 390

Dell Laptop Optiplex 390

Optiplex dual core 390

etc., etc.

Solution

  • For these sort of search capabilities I think you are looking for a matching algorithm. You can use the Levenshtein Distance Algorithm, there is a php function levenshtein that implement this algorithm if you are using php, to get the matching data and there is also Needleman–Wunsch algorithm, and if your data is in English only and one word column you can use Soundex Algorithm.

    This is a start, you will find a lot of implementations out there for these algorithms in Mysql.