我正在为我的程序实现一个搜索栏,它将根据用户输入查询数据库.当用户输入带有空格的单个搜索词(例如:I am searching for something
)时,程序会将其视为空格分隔值,并在数据库的多个相关列中搜索每个值.一个示例查询(基于上面的搜索短语)为:
SELECT * FROM TableName WHERE (
col1 LIKE "%I%" OR col2 LIKE "%I%" OR col3 LIKE "%I%" OR col4 LIKE "%I%" OR col5 LIKE "%I%"
OR col1 LIKE "%am%" OR col2 LIKE "%am%" OR col3 LIKE "%am%" OR col4 LIKE "%am%" OR col5 LIKE "%am%"
)
and so on for each space separated value in the input. As you can expect, this will be a very long query based on user input.
My question is, is there a better way to search for a single value in multiple columns? Or just a better way to implement a search like this one.