I would like to make a monthly contest. I have Users and Products. Each user can vote for products he/she likes the most this month. My vote table looks like this:
+---------+-----------+------------+
| user | product | date |
+---------+-----------+------------+
| 1 | 1 | 2018-09-03 |
| 1 | 2 | 2018-09-03 |
| 1 | 2 | 2018-08-28 |
+---------+-----------+------------+
A user can like the same product but not in the same month.
My problem is that I can't figure out a valid Primary Key to prevent duplicate votes.
If I use PK (user,product)
, a user cannot vote more than one time for the same product. If I use PK (user,product,date)
, a user can vote the same product once a day.
How can I prevent duplicate votes within the same month?
Note: date
should be a valid DateTime
column.