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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:40:46+00:00 2026-06-03T19:40:46+00:00

I have the tables accounts and action . accounts needs to be modified according

  • 0

I have the tables accounts and action. accounts needs to be modified according to the instruction stored in action.
In action each row contains an account-id, an action (i=insert, u=update, d=delete, x=invalid operation) and an amount by which to update the account.

  • On an insert, if the account already exists, an update should be done
    instead
  • On an update, if the account does not exist, it is created by an
    insert
  • On a delete, if the row does not exist, no action is taken

Input

accounts:

+---id----value--+
|   1  |   1000  |
|   2  |   2000  |
|   3  |   1500  |
|   4  |   6500  |
|   5  |    500  |
+----------------+

action:

+---account_id---o---new_value---status---+
|       3      | u |     599   |          |
|       6      | i |    2099   |          |
|       5      | d |           |          |
|       7      | u |    1599   |          |
|       1      | i |     399   |          |
|       9      | d |           |          |
|      10      | x |           |          |
+-----------------------------------------+

Output

accounts:

+---id----value--+
|   1  |    399  |
|   2  |    800  |
|   3  |    599  |
|   4  |   1400  |
|   6  |  20099  |
|   7  |   1599  |
+----------------+

action:

+---account_id---o---new_value-------------------status----------------+ 
|       3      | u |     599   | Update: Success                       |
|       6      | i |   20099   | Update: Success                       |
|       5      | d |           | Delete: Success                       |
|       7      | u |    1599   | Update: ID not founds. Value inserted |
|       1      | i |     399   | Insert: Acc exists. Updated instead   |
|       9      | d |           | Delete: ID not found                  |
|      10      | x |           | Invalid operation: No action taken    |
+----------------------------------------------------------------------+

I am experienced with Java and JDBC, but unfortunately I just don’t know, how to start here.
Do I need an additional table? Do I have to use triggers?

  • 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-03T19:40:47+00:00Added an answer on June 3, 2026 at 7:40 pm

    I’ve seen two techniques for an upsert. With the first technique, within a transaction, you test first to see if the row exists, and use the results to determine whether to perform an insert or an update. With the second technique, you try performing an update and verify the number of records updated (JDBC gives you this). If it’s zero, then you do an insert, if one, then you’re done.

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

Sidebar

Related Questions

I'm using MySQL I have three tables: accounts { account_id, username } account_ips {
I have 3 tables: users (id, name) currency (id, name) accounts (id, user_id, currency_id,
I have a set of tables (say Account, Customer) in a schema (say dbo)
I have a a user that has a lot of tables against their account.
In a table i have stored alot of datetimes for when a certain action
I have a MySQL table called accounts . Within this table is a field
In my table accounts I have four columns like user, pass, column1, column2 I
I have a table in MySQL that is titled accounts, inside of accounts I
I have a table as shown below. It has accounts of type Fixed and
I have a table that has account numbers in (account_num) and user profiles (profile_id).

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.