Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7859069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:45:36+00:00 2026-06-02T21:45:36+00:00

I am trying to pull a list of last 10 rows whose average rating

  • 0

I am trying to pull a list of last 10 rows whose average rating is above 4. Right now this is done by selecting from the first table and then checking the average if its above 4 then it gets added to a variable if not it does nothing. This is a horrible way to do this especially if there are over 1000 rows.

Here are the two queries:

SELECT * FROM `CLMS_reviews` WHERE id = 465 ORDER BY date DESC

SELECT 
rc.name, rr.rating
FROM `CLMS_reviews_ratings` rr  
LEFT JOIN `CLMS_reviews_categories` rc ON rc.cat_id = rr.cat_id  AND rc.website_id = 465
WHERE rr.review_id = " . $row['id'] . "
GROUP BY rc.name

How can I combine this into one query? I tried this but get an invalid use of GROUP BY:

SELECT 
rr.review_id
FROM `CLMS_reviews` r
LEFT JOIN `CLMS_reviews_ratings` rr ON rr.review_id = r.id
WHERE r.website_id = 465 AND AVG(rr.rating) > 4
GROUP BY rr.review_id LIMIT 10

SOLUTION From below:

SELECT review_id FROM `CLMS_reviews_ratings`
WHERE review_id IN ((SELECT id FROM `CLMS_reviews` WHERE website_id = 465))
GROUP BY review_id
HAVING avg(rating) > 4
LIMIT 10
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:45:39+00:00Added an answer on June 2, 2026 at 9:45 pm

    Cannot test it, but maybe this will do:

    SELECT rr.review_id
      FROM `CLMS_reviews` r
      LEFT JOIN `CLMS_reviews_ratings` rr ON rr.review_id = r.id
     WHERE r.website_id = 465
     GROUP BY rr.review_id
    HAVING avg(rr.rating) > 4
     LIMIT 10;
    

    If you need to filter on aggregate functions, HAVING is your freiend.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to pull rows from a table and list them in an ol, however,
I'm trying to pull out a list of table names from a MySQL database.
I'm trying to pull events from my google calendar into a list view (most
I'm trying to pull data from the last row inserted (_id) of a database.
I am trying to pull at list of resource/database names and IDs from a
I'm trying implement pull to refresh on a ListFragment but right now none of
I'm trying to write code to pull a list of product items from a
I'm trying to pull a report, (a pie chart or just a list) on
Using SQLite3 with Python 2.5, I'm trying to iterate through a list and pull
Just trying to pull off some SMART info from connected Hard Drives on any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.