I have an app where a user votes between two local profiles on which one is better. I want to ensure that the same user cannot vote more than once between the same two profiles (say the user votes on two different days or something), but I'm not sure what the most efficient way is to do this.

A simple solution is to have a table with 3 fields: voter (the user #), winner (the profile # who won), and loser (the profile # who lost). not necessarily gonna use those names, but I do want to use the data on who won/lost.

Is it horribly inefficient and stupid to send a request for every new matchup to search that table to see if the voter/votees have already been processed? If not, what are my options? Is it really that huge of a deal? Or should I instead allow repeat matchups and simply update the table fields accordingly if the voter's choice changes?

1 Answer 1


Here's how I would model the tables for that requirement (note the table and column names can be changed for whatever is appropriate for your application):

enter image description here

In this model, the idea of a "Profile" and "User" is contained in the same entity, "User". The idea of a single vote for one of two user candidates is contained in the entity "Vote". If you want to restrict a User to one Vote per set of two users, then you can add a unique index in Vote for idUser, idUserCandidate1, and idUserCandidate2.

  • Maybe I misunderstood this, but it seems like this is a good solution for if a contest were pre-made and meant to be voted on by many people. I should have specified this, but my app is kind of like tinder or the Lays Do Us A Flavor challenge where each matchup is unique to the voter if that makes any sense. thank you for the response!
    – ayy_lmao
    Commented Jun 19, 2015 at 21:31
  • Ah, ok. I updated the answer. Commented Jun 19, 2015 at 22:52
  • Just realized in the model there was no way to tell which user was voted for. updated again. Commented Jun 19, 2015 at 23:04
  • @ayy_lmao did this answer what you ask for? Close this question choising the answer. :)
    – oNare
    Commented Jul 1, 2015 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.