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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:26:12+00:00 2026-06-05T04:26:12+00:00

I have a table (TABLE1) which has 4 columns: UID | PID | VALUE1

  • 0

I have a table (TABLE1) which has 4 columns:

UID | PID | VALUE1 | VALUE2

I have another SQL statement (STMT) which returns 3 columns from some other tables:

UID | PID | VALUE1

Now here are the condition of how I want to update TABLE1:

First, compare UID and PID pair from STMT with those in TABLE1,

  1. for all new UID and PID pair not in TABLE1, insert new row from STMT into TABLE1, set TABLE1.VALUE2 = 0 (I’ve already done this one)

  2. for existing UID and PID pair in both STMT and TABLE1, do:

    a. if TABLE1.VALUE2 > 0, update TABLE1.VALUE1 = STMT.VALUE1

    b. if TABLE1.VALUE2 = 0 and if TABLE1.VALUE1 != STMT.VALUE1, update TABLE1.VALUE1 = STMT.VALUE1, otherwise do nothing.

I’m having trouble coming up with a solution for condition 2. Any help is appreciated!

  • 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-05T04:26:14+00:00Added an answer on June 5, 2026 at 4:26 am
    UPDATE (
        SELECT table1.UID
               ,table1.PID
               ,table1.value1 AS table1_value1
               ,table1.value2 AS table1_value2
               ,stmt.value1 AS stmt_value1
        FROM table1
        INNER JOIN (SELECT ? AS UID
                           ,? AS PID
                           ,? AS value1
                    FROM whatever) stmt
            ON stmt.UID = table1.UID
            AND stmt.PID = table1.PID
    ) x
    SET x.table1_VALUE1 = CASE WHEN (x.table1_VALUE2 > 0) OR
                                  (x.table1_VALUE2 = 0 AND x.table1_VALUE1 <> x.stmt_VALUE1)
                                  THEN x.stmt_VALUE1
                             ELSE x.table1_VALUE1 
                        END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table 'table1' which has 2 columns, flange_start and flange_end . I
I have a sql table images which has columns id , imagePath , caption``count
I have a sql table which has five columns Count1 float Count2 float Total
if i have a table which has columns with fixed lenght, Will mySQL count
Lets say I have two tables: table english which has two columns, id and
I have a table which has the below columns. Ticket_id (Primary key, Int) Attachment1
I have a table (participants) which has multiple columns that could all be distinct.
I have a table in HTML which has three columns i.e Error - User
I have a table called scheduler_sched which has several columns, including a column called
I have query table copyQuery which has Soil Condition has one of the columns,

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.