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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:11:52+00:00 2026-05-31T03:11:52+00:00

This should be a simple problem but I can’t seem to find an exact

  • 0

This should be a simple problem but I can’t seem to find an exact solution. This is basically what I have:

table_1:

id*   scenario*    val1     val2
---   --------     -----    ------
AC1    1            2        0
AC2    1            1        0 
AC1    2            4        0
AC2    2            3        0

table_2:

id*     val3
---     ------
AC1       4
AC2       6

All I want to do is update val2 of table_1 where scenario = 1 with values from table_2 with matching id but I want it to equal val1 + val3 (I don’t know how to make this less obfuscated). So for this example I want table_1 to become:

id*   scenario*    val1     val2
---   --------     ------   --------
AC1    1            2        6
AC2    1            1        7 
AC1    2            4        0
AC2    2            3        0

I think this can be done with a simple MySQL statement but I don’t know how to structure it with a condition for the first table (“INSERT INTO table_1 WHERE scenario=1 SELECT…”??) and the arithmetic of two columns from two different tables.

  • 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-31T03:11:54+00:00Added an answer on May 31, 2026 at 3:11 am

    Try this:

    UPDATE table_1 
    SET val2 = val1 + 
        (SELECT val3 FROM table_2
         WHERE id = table_1.id
         LIMIT 0,1)
    WHERE scenario = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be simple but I can't find a solution: I have a custom
This should be a simple problem, but I just can't seem to find a
This seems like a simple problem but I can't seem to find the answer.
Hey there, I have a simple problem but can't seem to get the solution
This should seem simple enough, but can't figure it out. I was porting a
This should be a simple problem, but I am have a tough time getting
This should be a really simple problem, but I can't quite figure out what
This should be fairly simple from what I can find online, but I can't
This should be a simple one, but I can't figure out the problem. I
This should be a simple question, but I can't seem to figure it out.

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.