如果我在当前表中执行搜索查询,就没有问题:
SELECT * FROM articles
WHERE CONCAT(title, content, author) LIKE '%searchstring%'
但是,如果我想包括联接表中的列,则无法将该列添加到where子句中:
SELECT articles.*, associations.name AS association_name
FROM articles
JOIN associations
ON articles.association_id = associations.id
WHERE CONCAT(title, content, author,association_name )
LIKE '%searchstring%'
错误变为"Unknown column 'association_name' in where clause"
那我如何在搜索查询中包括该列?
答案 0 :(得分:0)
只需写下注释中上面提供的答案即可。您应该这样做:
SELECT articles.*, associations.name AS association_name
FROM articles
JOIN associations ON articles.association_id = associations.id
WHERE CONCAT(title, content, author, associations.name)
LIKE '%searchstring%'