SELECT
*
FROM
company c
INNER JOIN
city ci ON ci.city_id = c.city_id
INNER JOIN
state s ON s.state_id = c.state_id
WHERE
MATCH (
c.name, ci.name, c.zipcode, s.name
)
AGAINST (
'los angeles'
)
答案 0 :(得分:12)
MATCH (...)
中的所有列必须来自同一个表,因为它们必须是全文索引的,并且MySQL无法为多个表中的数据创建一个索引。
答案 1 :(得分:8)
我遇到了同样的问题并解决了这个问题:
SELECT
*
FROM
company c
INNER JOIN
city ci ON ci.city_id = c.city_id
INNER JOIN
state s ON s.state_id = c.state_id
WHERE
MATCH (c.name) AGAINST ('los angeles')
OR MATCH (ci.name) AGAINST ('los angeles')
OR MATCH (c.zipcode) AGAINST ('los angeles')
OR MATCH (s.name) AGAINST ('los angeles')
但正如我所见,您正在搜索“name”和“zipcode”等简单字段。至于我,最好使用LIKE
并将它们连接起来
SELECT
*
FROM
company c
INNER JOIN
city ci ON ci.city_id = c.city_id
INNER JOIN
state s ON s.state_id = c.state_id
WHERE
CONCAT_WS (' ', c.name, ci.name, c.zipcode, s.name)
LIKE ('%los angeles%')