sqlcontains

SQL search for containing terms


Is it possible to search in a table for records of which its name contains a search term?


Solution

  • SELECT * FROM `my_table` WHERE name LIKE '%my_search_term%'
    

    or

    SELECT * FROM `my_table` WHERE CONTAINS(name, 'search')
    

    But be aware that the LIKE statement is very expensive. If you searching through a lot of text, you might want to consider using Sphinx for exemple.