我正在尝试使用以下JOIN查询获得相关的搜索结果:
SELECT
`products`.`id`,
`brands`.`name` AS `brand`,
`products`.`name` AS `productname`,
MATCH (`brands`.`name`) AGAINST ('somebrand someproduct' ) AS brandname_relevance
FROM
`brands`
INNER JOIN
`products` ON `products`.`brand_id` = `brands`.`id`
WHERE
MATCH (`products`.`name`) AGAINST ('somebrand someproduct' ) AS /* AS is highlighted as 'not valid input at this point' */ product_relevance
ORDER BY (brandname_relevance + product_relevance) DESC
但是,在此上下文中,MySQL Workbench将代码“ AS”突出显示为无效。查询失败。
两个表中的 Engine是InnoDB,但是MySQL服务器版本高于5.6,并且brands.name
和products.name
均启用了FULLTEXT索引。请在这里说明问题所在。
答案 0 :(得分:1)
在where子句中-将其与您选择的其他字段一起向上移动。
SELECT
`products`.`id`,
`brands`.`name` AS `brand`,
`products`.`name` AS `productname`,
MATCH (`brands`.`name`) AGAINST ('somebrand someproduct' ) AS brandname_relevance,
MATCH (`products`.`name`) AGAINST ('somebrand someproduct' ) AS product_relevance
FROM
`brands`
INNER JOIN
`products` ON `products`.`brand_id` = `brands`.`id`
ORDER BY (brandname_relevance + product_relevance) DESC