我試圖將用戶輸入的搜索詞與兩個表匹配:帖子和畫廊。問題是union all子句不起作用。我的代碼有問題嗎?爲什麼這個簡單的MySQL語句不工作?
$query = mysql_query("
SELECT * FROM posts WHERE title LIKE '%$searchTerm%'
OR author LIKE '%$searchTerm%'
OR location LIKE '%$searchTerm%'
OR excerpt LIKE '%$searchTerm%'
OR content LIKE '%$searchTerm%'
UNION ALL
SELECT * FROM galleries WHERE title LIKE '%$searchTerm%'
");
什麼不起作用? 這些表格是否有相同的列? – Wolph 2010-04-06 23:23:55