I have a query like this:
SELECT TPCombined.Title,
GROUP_CONCAT(DISTINCT CONCAT(a.LastName, ', ', a.FirstName) SEPARATOR '<br />') as Author
FROM ((SELECT b.Title FROM BookList b) UNION (SELECT s.Title FROM Studios s))
AS TPCombined
LEFT OUTER JOIN (AuthorLinks al JOIN Authors a ON al.AuthorStem = a.AuthorStem)
ON TPCombined.BookStem = al.BookStem
WHERE Author LIKE '%Smith%' GROUP BY BookStem;
This query doesn’t work:
Unknown column ‘Author’ in ‘where clause’
This would work with HAVING instead of WHERE. But I really need to use Where. Could you please confirm if this is really impossible? Or maybe I can fix the query somehow to make it work with Where?
WHERE clauses are applied at the row level. You’ve aliased an aggregate function as Author, which means its results won’t be available at the row level – only when the query is complete and ready to go to the client. You’d need to use a HAVING filter instead, which is applied just before sending to client.