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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:19:13+00:00 2026-06-18T14:19:13+00:00

I have a requirement to update a record if it exists else insert it.

  • 0

I have a requirement to update a record if it exists else insert it. I know this has been asked a few times but I think my problem is a bit trickier.

I have a table (tbl_settings):

setting_id   |    token   |   setting_value   |   setting_for
1                 1           on                  background
2                 1           off                 vibrate
3                 2           on                  vibrate

etc

This is for a mobile app which I will save the users settings in a remote DB so the can retrieve later if needed.

Setting_id is unique and auto increment.

Token is going to be the devices token id (user specific)

Setting_value is the value (on/off) for that particular setting

Setting_for is the name of the actual setting

Now there are 4 setting options available to a user which can be written to the DB at individual times (when the user changes the setting on/off) or together if its better.

So if the user changes the vibrate setting, I need a query to check if vibrate and token exist update that particular record otherwise insert with token, setting_value and setting_for.

Hopefully its possible in a single query. If not I will just use multiple queries, one to check if it exists and the other to insert or update.

  • 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-18T14:19:15+00:00Added an answer on June 18, 2026 at 2:19 pm

    MySQL offers two options for this:

    • replace into
    • insert ... on duplicate update

    Do note that in both cases you’ll have to drop your setting_id (which seems pointless anyway) and use a composite primary key.

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

Sidebar

Related Questions

I have a requirement to update IE mode to latest version. How to know
I have updated this script. The dynamic dropdown portion of the script requirement has
I have this requirement that i need to Update/Save all records from DatabaseA on
This is pretty easy question, but I have been unable to find the solution
I have lot of products with custom options, now I have requirement to update
I have a requirement where i have to update a textbox if any of
My requirement is that I want an object (tee) to update if there have
I have requirement where some times I would like to load children as well
I have requirement to disable copy/paste/cut operations on a textbox. For this purpose I
I have requirement like, suppose I have a 'property' table which has 'ListingKey' field

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.