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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:26:18+00:00 2026-05-14T00:26:18+00:00

I’m fairly new to working with relational databases, but have read a few books

  • 0

I’m fairly new to working with relational databases, but have read a few books and know the basics of good design.

I’m facing a design decision, and I’m not sure how to continue. Here’s a very over simplified version of what I’m building: People can rate photos 1-5, and I need to display the average votes on the picture while keeping track of the individual votes. For example, 12 people voted 1, 7 people voted 2, etc. etc.

The normalization freak of me initially designed the table structure like this:

Table pictures
id* | picture | userID | 

Table ratings
id* | pictureID | userID | rating

With all the foreign key constraints and everything set as they shoudl be. Every time someone rates a picture, I just insert a new record into ratings and be done with it.

To find the average rating of a picture, I’d just run something like this:

SELECT AVG(rating) FROM ratings WHERE pictureID = '5' GROUP by pictureID 

Having it setup this way lets me run my fancy statistics to. I can easily find who rated a certain picture a 3, and what not.

Now I’m thinking if there’s a crapload of ratings (which is very possible in what I’m really designing), finding the average will became very expensive and painful.

Using a non-normalized version would seem to be more efficient. e.g.:

Table picture
id | picture | userID | ratingOne | ratingTwo | ratingThree | ratingFour | ratingFive

To calculate the average, I’d just have to select a single row. It seems so much more efficient, but so much more uglier.

Can someone point me in the right direction of what to do? My initial research shows that I have to “find the right balance”, but how do I go about finding that balance? Any articles or additional reading information would be appreciated as well.

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-05-14T00:26:18+00:00Added an answer on May 14, 2026 at 12:26 am

    Your normalized approach makes a lot of sense, the denormalized one doesn’t.


    In my experience (Telco Performance Management, hundreds of thousands of datapoints per 1/4 hour) we would do the following:

    Table: pictures
    id* | picture | userID | avg_rating | rating_count
    
    Table: ratings
    id* | pictureID | userID | rating
    

    For the telco the pictures rating would be re-calculated once daily, you should do it periodical (e.g. hourly )or every time you insert (re-calc for the picture rated, not the entire table). This depends on the amounts of ratings you get.


    In the telco we also keep the rating-date in what is your ‘pictures’ table and a 1/4h timestamp in the ratings table, but I don’t think you need that level of detail.


    The ‘denormalization’ is to move a calculateable fact (count (rating) and avg(rating)) to the pictures table. This saves CPU cycles, but costs more storage.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.