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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:45:19+00:00 2026-06-17T19:45:19+00:00

I have a table with products and a table with ratings. I have the

  • 0

I have a table with products and a table with ratings. I have the following query;

SELECT products.name, ratings.rating 
FROM   products 
       LEFT OUTER JOIN ratings 
       ON products.id = ratings.product_id;

Returning me a nice list of rows with the name of the product and every rating separately.

I am trying to achieve that it returns one row showing me the name of the product with its average rating. Can’t seem to find out how though.

Thanks in advance.

  • 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-17T19:45:20+00:00Added an answer on June 17, 2026 at 7:45 pm

    You want to look into the GROUP BY statement. Example:

    SELECT products.name AS Product_Name, 
           AVG(ratings.rating) AS Average_Rating
    FROM   products 
           LEFT OUTER JOIN ratings 
           ON products.id = ratings.product_id
    GROUP BY products.name
    ORDER BY products.name;
    

    Whilst using the GROUP BY statement, you may wish to filter your resultset on the outcome of one or more of your aggregate functions. You use the HAVING statement to do so:

    SELECT products.name AS Product_Name, 
           AVG(ratings.rating) AS Average_Rating
    FROM   products 
           LEFT OUTER JOIN ratings 
           ON products.id = ratings.product_id
    GROUP BY products.name
    HAVING AVG(ratings.rating) >= 3
    ORDER BY products.name;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table 'products' => ('product_id', 'name', 'description') and a table 'product_price' =>
I have a table products: product_id product_name prodcut_price My dbcontext name is abcentity .
I have a table products , and I have columns like product_name , product_id
I have a table of products, and I need to write an SQL query
Basically I have a table Products with Product_ID and table Sub_Categories with Sub_Category_ID. Products
I have following table structure table domains ID | name | ________________________ 1 |
Hi I Have a table which has number of products and rating for each,
I have a table with products Id | Name | Order 1 | product
hi i have table called products with columns product_id prodcut_name prodcut_price( values like 1200,2000,3000,100)
I have a table hall_products with products. Each product has a NAME, is sold

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.