2017-03-01 56 views
0

我有以下條件的查詢執行多個列的搜索MySQL的多列搜索返回錯誤結果

SELECT 
    prod.pid, 
    prod.pname, 
    prod.description, 
    prod.status, 
    foto.set_cover, 
    foto.filename 
FROM products prod 
INNER JOIN second_child_categories secd ON prod.category_id = secd.second_id 
INNER JOIN photos foto ON prod.pid = foto.pid 
WHERE CONCAT(prod.pname, prod.description) LIKE '%home%' 
OR CONCAT(prod.description, prod.pname) LIKE '%home%' 
AND foto.set_cover = '1' 
AND prod.status = '1' 
ORDER BY prod.created_date DESC 

下面是輸出:

enter image description here

作爲參考查詢,我所設定的條件:

foto.set_cover='1' AND prod.status='1' 

結果與condit不匹配離子。

我該如何解決這個問題?

謝謝。

回答

0

Mysql or/and precedence?

OR具有更高的優先級,你(隱含的)寫道:

CONCAT(prod.pname, prod.description) LIKE '%home%' 
OR (
    CONCAT(prod.description, prod.pname) LIKE '%home%' 
    AND foto.set_cover = '1' 
    AND prod.status = '1' 
) 

什麼,我想你的意思

( 
    CONCAT(prod.pname, prod.description) LIKE '%home%' 
    OR 
    CONCAT(prod.description, prod.pname) LIKE '%home%' 
) 
AND foto.set_cover = '1' 
AND prod.status = '1'