Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Using Mysql Alias in WHERE

SpaceshipSpaceship
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by 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.
GoDaddyGoDaddy
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

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

Watched threads: your alert now keeps up with new replies
When you watch a thread, each new reply now updates your alert. Before, you got one alert and then nothing until you read the thread...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back