Unstoppable Domains โ€” AI Assistant

Using Mysql Alias in WHERE

SpaceshipSpaceship
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.
Unstoppable Domains โ€” AI StorefrontUnstoppable Domains โ€” AI Storefront
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
•••
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy โ€” Live Options
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back