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 7003261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:02:40+00:00 2026-05-27T21:02:40+00:00

Okay, so I got 2 tables. One holds the recipes, and the second all

  • 0

Okay, so I got 2 tables. One holds the recipes, and the second all the ratings.

recipes_ratings:
id, rating, user_id, recipe_id

recipes:
id, name

I would like to count all the rows for each recipe. Then sort and show the recipes that are most rated and descending.

What is the simplest way to do? I have thought to make a query

SELECT * FROM recipes_ratings

And then count with a loop through the ratings, and store into array, and then sort out from that.

But can it be done simpler? One query only to do it all..or?

  • 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-05-27T21:02:41+00:00Added an answer on May 27, 2026 at 9:02 pm

    Depending on how you want to calculate the overall rating per recipe, you might need to adapt the calculation. But the query should be something like this:

    SELECT r.id, product, avg(rating) as average_rating
    FROM recipes r 
    LEFT JOIN recipes_ratings rr 
        ON (r.id=rr.recipe_id)
    GROUP BY id 
    ORDER BY 3 desc;
    

    Beware, that this will also output recipes without any rating. If you don’t want to have them returned, change LEFT JOIN to JOIN.

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

Sidebar

Related Questions

Okay, so I've got this TableLayout, and its full of data - with all
Okay I've got my app.config file that is containing my database settings. All works
Okay, so I have these two tables in MySQL. One is called 'History' and
Okay, so I've got a class where one of the attributes is a callback
Okay so i got one table with people. One table with items that are
I'm checking my code for memory leaks. Everything is okay until I got the
Okay, I have GOT to be missing something totally rudimentary here. I have an
Okay, so we've got this event. Awesome, right? We've also got a timer with
Okay, so I've got the following code shown below to create a dialog using
Okay, so I've got a problem - and I'd love to have it fixed.

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.