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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:17:08+00:00 2026-05-24T22:17:08+00:00

I have a table with with essentially three columns: user_id, setting, and value. I’m

  • 0

I have a table with with essentially three columns: user_id, setting, and value. I’m trying to use the following code:

INSERT INTO 'user_settings'(user_id, setting, value)
VALUES (1234, setting_1, 500)
ON DUPLICATE KEY UPDATE user_id = 1234, setting = setting_1'

This works great when creating a new setting, and it doen’t generate duplicate records. The problem comes when I want to change the value- this won’t work after the previous query has run:

INSERT INTO 'user_settings'(user_id, setting, value)
VALUES (1234, setting_1, 999)
ON DUPLICATE KEY UPDATE user_id = 1234, setting = setting_1'

No rows are affected. Clearly I’m missing something…

IMPORTANT: I am not able to alter the database (new primary keys or something).

UPDATE: It seems my understanding of ON DUPLICATE KEY is wrong. But the question remains- what is the most efficient way way to accomplish this?

Answered in a comment below: “If the Primary (or Unique) key is (user_id, setting), then use: … ON DUPLICATE KEY UPDATE value=999”.

  • 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-24T22:17:08+00:00Added an answer on May 24, 2026 at 10:17 pm

    Assuming you actually have a unique key on user_id, you are getting “no rows affected” because you aren’t changing anything in the second query. I think what you want to do is update the value field as well:

    INSERT INTO 'user_settings'(user_id, setting, value)
    VALUES (1234, setting_1, 999)
    ON DUPLICATE KEY UPDATE setting = setting_1,value=999
    

    Without value in there, you’re just setting the user_id and the setting field to the same values they were before, and MySQL doesn’t need to update the record.

    If you don’t have a unique key on user_id, you’ll have to find a different approach, as the ON DUPLICATE KEY UPDATE won’t trigger.

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

Sidebar

Related Questions

I have a table containing (essentially) three columns - id, name, ref_id. I would
I have one table with 2 columns that i essentially want to split into
I have a table which has essentially boolean values in a legacy database. The
I have a table schema which is essentially a bunch of transaction info with
I have a table populated with time stamped rows inserted at (essentially) random point
I have table with some fields that the value will be 1 0. This
I have table with 3 columns A B C. I want to select *
I have a table and want to transpose its rows to columns, similar to
I have two columns in my Items table 'Category', 'Category2', the two columns contain,
I have a table where i have columns such as: deposit_received paperwork_received preferred_physician preferred_physician_phone

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.