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

  • Home
  • SEARCH
  • 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 9132381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:18:09+00:00 2026-06-17T08:18:09+00:00

My current DB table looks like this: CREATE TABLE IF NOT EXISTS `image_ratings` (

  • 0

My current DB table looks like this:

CREATE TABLE IF NOT EXISTS `image_ratings` (
 `rating_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
 `user_id` int(11) unsigned NOT NULL,
 `photo_id` int(11) unsigned NOT NULL DEFAULT '0',
 `rating` tinyint(3) unsigned NOT NULL DEFAULT '0',
 `rated_user_id` int(11) unsigned NOT NULL,
 `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 PRIMARY KEY (`rating_id`),
 KEY `user_id` (`user_id`),
 KEY `rated_user_id` (`rated_user_id`),
 KEY `photo_id` (`photo_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

When I make a call like so:

INSERT INTO image_ratings (user_id, photo_id, rating, rated_user_id) VALUES (5, 5975, 8, 5973 ) ON DUPLICATE KEY UPDATE user_id=5, photo_id=5975, rating=8, rated_user_id=5973, timestamp=NOW() 

It creates a new entry even though I already have any entry for the same user_id, rated_user_id, and photo_id. Is this because I have a PRIMARY key defined for the rating_id?

I would expect it to update the existing entry with the new rating value.

Any thoughts?

  • 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-17T08:18:10+00:00Added an answer on June 17, 2026 at 8:18 am

    You need a UNIQUE index on the compound key that defines the unique tuple you’re looking for. In your case, it seems like user_id and photo_id would be relevant. Without this the only unique key is the rating_id which will be populated automatically for you every time.

    Also, please don’t use MyISAM on important production databases. It’s very brittle compared to InnoDB and will end up corrupted beyond repair sooner or later.

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

Sidebar

Related Questions

I have a table that looks like this: Id (PK, int, not null) ReviewedBy
I have a db-table that looks like this: CREATE TABLE ItemPrice ( [Identity] INT
Imagine a database table that looks like this: create table [dbo].[user] ( id int
Given this table: CREATE TABLE [Comments] ( [Id] [int] IDENTITY(1, 1) NOT NULL, [Text]
I have a MySQL Table that looks like this: The SQL to create the
I have a table that looks something like this: CREATE TABLE A ( A_UNIQUE_ID
How do you create a temporary table exactly like a current table in a
My current script looks something like this: !/bin/sh sudo -u postgres createdb mydb sudo
I've got a table that looks like this: Code Mark Date Notional Beta 5/1/2008
At a glance, the database schema looks like this: The schema has to be

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.