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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:30:39+00:00 2026-05-20T12:30:39+00:00

I have recently started playing with databases, trying to teach myself using examples. I

  • 0

I have recently started playing with databases, trying to teach myself using examples.

I have the following problem that I’m currently trying to solve which confuses the hell out of me and I’m hoping that someone can shed some light.

The database has 4 tables. Photographers, Pictures, Competition and Viewers. The concept is that photographers take part in competitions. They shoot 1 picture for each competition and viewers rate it. The winner of the competition is the one who gets most points. I have put the following restrictions.

  1. Ratings are between 0 – 5
  2. Only the first 20 viewers can vote
  3. I don’t want to store the total rating of the photographer as I want to learn how to calculate derived values.

For numbers 1 & 2 – I’m not sure how to explicitly create this constraint.
For number 3, I don’t know how to represent derived values on the db.
I’m using MySql

Any thoughts, advice would be greatly appreciated!

Best Regards

  • 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-20T12:30:39+00:00Added an answer on May 20, 2026 at 12:30 pm

    1] You can’t set such constraint directly in MySQL as far as I know. you could use UNSIGNED TINYINT with allowed values of 0-255 but you have to check yourself if the values are ok before inserting them into the database.

    2] Do I understand you correctly that you want to allow only a maximum of 20 votes per picture?

    You’d either have to store all the votes in a separate (then check for the number of votes already present) or save just the average and number of votes. Either way, you have to check for this yourself and determine if you allow the user to vote or not. For the first option:

    SELECT COUNT(*) > 20 FROM votes
    WHERE picture_id = '123'
    

    For the second even simpler:

    SELECT votes_count > 20 FROM pictures
    WHERE id = '123'
    

    3] If you had your votes for the pictures stored directly in the pictures db, you simply use the SUM() function:

    SELECT *, SUM(points) as total_points FROM photographers AS ph
    LEFT JOIN pictures AS pic ON pic.photographer_id = ph.id
    GROUP BY p.id, competition_id
    

    I hope I made no mistakes there. If you have more detailed question, please just ask, I’ll try to fill the holes 😉

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

Sidebar

Related Questions

I have recently started using Netbeans with following stack Liferay, icefaces with jBoss. Is
I have recently started teaching myself C# and Asp.net. I am trying to build
I have recently started to learn Objective-C and write my tests using OCUnit that
Recently I have started playing with jQuery, and have been following a couple of
I have recently started using Behat with Mink on a PHP project that uses
I have recently started using Vim as my text editor and am currently working
I have started playing around with Apache camel recently. So being the experimental type
I have recently started to use Twitter Bootstrap and trying to understand how it
I have recently started using RSpec for Integration testing in my Rails application, to
I have recently started using DocCheck for checking the validity of JavaDoc's in code

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.