Dynadot โ€” .com Registration $8.99

Using Mysql Alias in WHERE

Spaceship Spaceship
Watch

ridesign1

Established Member
Impact
7
I am trying to execute the following query but I get unknown column for rating_score for the WHERE clause.

Code:
SELECT SUM(ratings.rating_rating) AS rating_score, posts.ID, posts.post_title FROM posts LEFT JOIN ratings ON ratings.rating_postid = posts.ID WHERE rating_score >= 1 GROUP BY posts.ID ORDER BY posts.post_date DESC LIMIT 5
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
MySQL ?
Use the full expression instead of the alias.
In aggregate expression use the HAVING clause instead of WHERE.
Fields that are not aggregated should be included in group by statement.

Something like this perhaps:

Code:
SELECT SUM(ratings.rating_rating) AS rating_score, posts.ID, posts.post_title 
FROM posts LEFT JOIN ratings ON ratings.rating_postid = posts.ID 
HAVING SUM(ratings.rating_rating) >= 1 
GROUP BY posts.ID, posts.post_title
ORDER BY posts.post_date DESC 
LIMIT 5
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back