1
我試圖執行與下面的查詢搜索:通過連接表搜索只顯示一個表的數據匹配
SELECT
*
FROM
question_index
JOIN
question_content
ON question_index.id = question_content.question_id
WHERE
question_index.remove = '0' AND
question_index.active = '1' AND
question_index.publish_date <= '$current_time' AND
(
question_index.question LIKE '%$keyword%' OR
question_content.text LIKE '%$keyword%'
)
GROUP BY
question_index.id
ORDER BY
question_index.publish_date DESC
我想要做的是關於搜索通過表和顯示運行結果匹配「question_index.question」或「question_content.text」
但現在,它只顯示匹配「question_content.text」的結果。我試圖刪除「question_content.text LIKE'%$ keyword%'」但沒有結果出現。我可以得到匹配「question_index.question」結果的唯一方法是如果我一起刪除聯接。但那不是我想要的結果。
由於您剛加入'',因此默認情況下正在執行'內部'連接,這意味着您將在連接的兩邊存在記錄的情況下獲得結果。如果你想從一邊看所有記錄,即使在另一邊沒有匹配,你也需要使用「左連接」或「右連接」。 –
左聯合工作!請將它作爲答案提交,我會接受它,thx! –