我有三个信息表,其中business_id是公共线程。我有两个输入字段,一个用于一般搜索(用户可以搜索他们想要的任何内容)和一个zip输入。在php方面,我抓住了常规搜索字符串并将其设置为$search
,并将zip设置为$zip
。
如何使用$search
变量MATCH
使用$zip
任何全文缩进 然后 限制这些匹配 然后 只返回表c中的id?
我的数据库结构如下:
table coup
id << this is the my desired information from the search
timestamp
business_id
coupvalue
startdate
enddate
username
status
terms
image
description
primary = id
fulltext = name
table bloc
id
address
city
state
zip
business_id
phone
lat
lon
primary = id
table bus
business_id
name
timestamp
category
subcat
primary = business_id
fulltext = name,category,subcat
任何帮助将不胜感激!
答案 0 :(得分:0)
您可以对匹配项使用or
条件:
select
c.id
from
coup c
inner join bus b on
c.business_id = b.business_id
inner join block z on
c.buisness_id = z.business_id
where
(match(c.name) against ('$search')
or match (b.name, b.category, b.subcat) against ('$search'))
and z.zip = '$zip'
我没有对它进行基准测试,但这可能会更快:
select
c.id
from
(select id, business_id
from coup
where match(name) against ('$search')
) as c
left join
(select business_id
from bus
where match(name, category, subcat) against ('$search')
) as b on
c.business_id = b.business_id
inner join bloc z on
c.business_id = z.business_id
where
z.zip = '$zip'