6

UNIONSを使用して複数のテーブルに対してMATCH()AGAINST()の結果を返そうとしていますが、唯一の問題は、一部の行が関連性0を返すことです。これらを除外したいと思います。組合の後、「WHERErelevance>0」を使用する方法があります

以下は私のSQLのビットです

SELECT pages.content AS search, page_info.url AS link, MATCH(pages.content) AGAINST('Wales') as relevance 
FROM page_content
LEFT JOIN pages ON (page_info.page = pages.id)

UNION

SELECT products_real.name AS search, products_real.event AS link, MATCH(products_real.name, products_real.description) AGAINST ('Wales') as relevance
FROM product_real

ORDER BY relevance DESC

とにかく、ORDERBYの前にWHERErelevance>0を追加できますか?

どうもありがとう

4

2 に答える 2

4

派生テーブルを使用してみてください

SELECT * 
FROM
  (SELECT 
    pages.content AS search, 
    page_info.url AS link, 
    MATCH(pages.content) AGAINST('Wales') as relevance  
  FROM page_content 
  LEFT JOIN pages ON (page_info.page = pages.id) 
  UNION 
  SELECT 
    products_real.name AS search, 
    products_real.event AS link, 
    MATCH(products_real.name, products_real.description) AGAINST ('Wales') as relevance 
  FROM product_real) myQuery
Where myQuery.relevance <> 0
ORDER BY myQuery.relevance DESC
于 2010-07-07T13:44:22.963 に答える
2

各クエリまたは最後に追加できます。

SELECT pages.content AS search, page_info.url AS link, MATCH(pages.content) AGAINST('Wales') as relevance 
FROM page_content
LEFT JOIN pages ON (page_info.page = pages.id)
WHERE relevance > 0

UNION

SELECT products_real.name AS search, products_real.event AS link, MATCH(products_real.name, products_real.description) AGAINST ('Wales') as relevance
FROM product_real
WHERE relevance > 0

ORDER BY relevance DESC



SELECT search, relevance FROM
(

SELECT pages.content AS search, page_info.url AS link, MATCH(pages.content) AGAINST('Wales') as relevance 
FROM page_content
LEFT JOIN pages ON (page_info.page = pages.id)

UNION

SELECT products_real.name AS search, products_real.event AS link, MATCH(products_real.name, products_real.description) AGAINST ('Wales') as relevance
FROM product_real
) D
WHERE relevance > 0
ORDER BY relevance DESC
于 2010-07-07T13:46:45.643 に答える