[英]Select from two tables with same column name mysql
我有兩個表需要select * from
中select * from
。 我正在構建一個搜索代碼。
這是我的查詢:
SELECT articles.*, news.* FROM articles, news WHERE title LIKE '%$search%' OR short_description LIKE '%$search%' OR author LIKE '%$search%' OR date LIKE '%$search%' LIMIT 15
我收到此錯誤:
Error
SQL query: Documentation
SELECT articles.*, news.* FROM articles, news WHERE title LIKE '%$search%' OR short_description LIKE '%$search%' OR author LIKE '%$search%' OR date LIKE '%$search%' LIMIT 15
MySQL said: Documentation
#1052 - Column 'title' in where clause is ambiguous
嘗試這個?
SELECT a.*, n.* FROM articles a,
join news n on a.____ = n.______
WHERE a.title LIKE '%$search%' OR a.short_description LIKE '%$search%'
OR n.author LIKE '%$search%' OR n.date LIKE '%$search%'
LIMIT 15
您需要添加別名,我已經在下面猜測 LIKE 語句可以從中提取的每個表。 您需要自己將 a.___ 替換為正確的標識符。
更改舊的 JOIN 語法也可能值得。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.