Php 如果值类似于多个列,则选择SQL列

Php 如果值类似于多个列,则选择SQL列,php,mysql,sql,search,autocomplete,Php,Mysql,Sql,Search,Autocomplete,我需要用ajax创建一个自动完成搜索。建议应仅包含输入最多的10个结果。如果值类似于我的变量,则搜索查询必须检查多个列 但我的问题是创建查询和php逻辑 有插件或类似的东西吗? 如果列中的值类似于我的变量,如何选择该列? 我需要创建一个count查询,它在所有列中计算完整单词被空格分隔的频率为什么不在这里使用union all select department from entries where department like '%myVariable%' union all select

我需要用ajax创建一个自动完成搜索。建议应仅包含输入最多的10个结果。如果值类似于我的变量,则搜索查询必须检查多个列

但我的问题是创建查询和php逻辑

有插件或类似的东西吗? 如果列中的值类似于我的变量,如何选择该列?
我需要创建一个count查询,它在所有列中计算完整单词被空格分隔的频率为什么不在这里使用union all

select department from entries where department like '%myVariable%'
union all
select grade from entries where grade like '%myVariable%'
然后,这将为您排序结果:

select department, count(*) cnt from (
select department from entries where department like '%myVariable%'
union all
select grade from entries where grade like '%myVariable%')a
group by department
order by count(*) desc
select department, count(*) cnt from (
select department from entries where department like '%myVariable%'
union all
select grade from entries where grade like '%myVariable%')a
group by department
order by count(*) desc