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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:55:21+00:00 2026-06-12T00:55:21+00:00

I’ve searched quite a while but I did not find an answer for my

  • 0

I’ve searched quite a while but I did not find an answer for my question. First let me explain where my question comes from.

I have a web-application that has a user-form in which the user can specify on which days of the week he/she is available and what the office times are at this days. Imagine this as a webform with checkboxes for mo-su and from-time, to-time dropdowns for each checkbox/day. Now if a user profile was inserted to the database table I have something like this in my table:

idUser | idDay | fromTime | toTime

     1 |     0 |    08:00 |  09:00

(in this example 0 stands for Monday (0=mo – 6=su))

Of course there is the feature to change the users profile. So it might be possible that first the user was available mo-fr from 5am to 3pm. Now the profile is changed so that the user is only available mo, fr from 5am to 3pm and we, th only till 1pm AND on sa from 9am-5pm, In this case I have to update the existing entries, to delete the removed entries (tue in this example) and to insert the new available days.

Right now I first delete all entries for the user and the I perform a new insert. This is quite easy and in this case probably the best thing to do (because there are max. 7 entries for each user). BUT the same problem could appear in a different situation where it might be better to optimize the query.

So finally my question is: Is it possible to perform an update if exists, insert if not and delete all other entries in just ONE query?

I hope my question is understandable.

  • 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-12T00:55:22+00:00Added an answer on June 12, 2026 at 12:55 am

    The simplest thing is just to delete all instances then create a new schedule for the updated entries. It sounds like you are trying to do some premature optimisation of the process which IMHO will not be necessary. If you find that deleting all existing entries and replacing them is a performance bottleneck then you might want to consider using an approach which tries to minimise the additional inserts but I think that this would probably end up actually being more work than the simpler option of just removing everything and replacing it

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

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from

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.