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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:50:31+00:00 2026-06-06T10:50:31+00:00

First off, I am not very good with MySQL yet, so go easy on

  • 0

First off, I am not very good with MySQL yet, so go easy on me. I am not even sure how to word my question.

I have two tables; one table contains information about links, the other ratings of each link made by users. Essentially, I just need to be able to order the links table by rating average.

TABLES:

links

  • link_id PK int autoincrement
  • url varchar
  • title varchar
  • description text
  • rating decimal

link_ratings

  • link_rating_id PK int autoincrement
  • link_id FK int
  • user_id FK int
  • rating decimal

What I need is when someone adds a link rating to a link (new link_ratings entry) or updates their current rating, all of the ratings for that link are averaged and updated on the rating column in links. OR Can I scrap the rating column in the links table entirely and use a JOIN?

If so, how would I go about doing the JOIN. If not, how do I make TRIGGER that would accomplish this for me?

I haven’t been able to find much information, most likely due to my lack of SQL knowledge, of how to even start this.

Any help is appreciated. Thanks.

  • 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-06T10:50:31+00:00Added an answer on June 6, 2026 at 10:50 am

    You don’t need to persist the rating average in the links table. I am calculating it below, and this should perform reasonably well:

    select l.link_id,
        l.url,
        l.title,
        l.description,
        lra.AvgRating
    from links l
    left outer join (
        select link_id, avg(rating) as AvgRating
        from link_ratings
        group by link_id
    ) lra on l.link_id = lra.link_id
    order by lra.AvgRating desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, I'm not entirely sure that my question title is very descriptive, so
First off , my english is not very good so be nice :) My
First off, I'm not an expert with MySQL queries, and I can't seem to
I know I can read off /proc/[id]/maps but I'm not sure if the first
First off, I'm not terribly experienced in XML. I know the very basics of
First off good day and thanks for taking the time to answer my question.
First off I apologize... I have posted this question before, but I did a
First off I want to say that I am not using threads or multiple
First off, I am not a DBA, but I do work in an environment
First off, this is NOT a duplicate of: Turn a C string with NULL

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.