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

  • Home
  • SEARCH
  • 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 9201093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:55:20+00:00 2026-06-17T22:55:20+00:00

https://stackoverflow.com/a/11177086/1947965 from the correct answer link above I want to follow up another question.

  • 0

https://stackoverflow.com/a/11177086/1947965

from the correct answer link above I want to follow up another question. because all I want to do is update set of fields when the this set of fields are empty else update to another set of fields not just only a single column.
Here is another situation:

1.) If subjectColumnA, timeColumnA, dataColumnA is NULL update fields.

2.) If subjectColumnA, timeColumnA, dataColumnA is Not NULL AND subjectColumnB, timeColumnB, dataColumnB is NULL update fields subjectColumnB, timeColumnB, dataColumnB

and so on. . .

From @ravinder’s query I want to ask having this scenario:
Let us say this is the content of the table

+------+------+------+------+------+------+------+------+------+------+
| id   | AAA1 | BBB1 | CCC1 | AAA2 | BBB2 | CCC2 | AAA3 | BBB3 | CCC3 |
+------+------+------+------+------+------+------+------+------+------+
|    1 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
+------+------+------+------+------+------+------+------+------+------+

From the condition above I mention ‘AAA1, BBB1, and CCC1’ is NULL so this columns will be updated. And the result will be like this.

+------+------+------+------+------+------+------+------+------+------+
| id   | AAA1 | BBB1 | CCC1 | AAA2 | BBB2 | CCC2 | AAA3 | BBB3 | CCC3 |
+------+------+------+------+------+------+------+------+------+------+
|    1 |    2 |    2 |    2 | NULL | NULL | NULL | NULL | NULL | NULL |
+------+------+------+------+------+------+------+------+------+------+

Another instances is that when ‘AAA1, BBB1, CCC1’ is ‘NOT NULL’ then ‘AAA2, BBB2, and CCC2’ will be updated which the result will be like this.

+------+------+------+------+------+------+------+------+------+------+
| id   | AAA1 | BBB1 | CCC1 | AAA2 | BBB2 | CCC2 | AAA3 | BBB3 | CCC3 |
+------+------+------+------+------+------+------+------+------+------+
|    1 |    3 |    3 |    3 | NULL | NULL | NULL | NULL | NULL | NULL |
+------+------+------+------+------+------+------+------+------+------+

Is it possible?? Since what I have read from others questions and the answers Using CASE and If uses 2 arguments only. I tried this querying like this one but it fails.

UPDATE table SET
    AAA3 = IF( AAA2 IS NOT NULL, 2, AAA3 ) AND BBB3 = IF( BBB2 IS NOT NULL, 2, BBB3 ),
    AAA2 = IF( AAA1 IS NOT NULL, 2, AAA2 ) AND BBB2 = IF( BBB1 IS NOT NULL, 2, BBB2 ),
    AAA1 = IF( AAA1 IS NULL, 1, AAA1 ) AND BBB1 = IF( AAA1 IS NULL, 1, BBB1 );
  • 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-17T22:55:21+00:00Added an answer on June 17, 2026 at 10:55 pm

    Really hard to answer this without having sample data and desired output, but using the link you supplied and your pseudo syntax above, you should be able to do it the exact same way:

    UPDATE TableName SET 
    subjectColumnA = ( case when subjectColumnA is null 
                            AND timeColumnA is null 
                            AND dataColumnA is null 
                        then ? 
                        else subjectColumnA end ),
    timeColumnA = ( case when subjectColumnA is null 
                            AND timeColumnA is null AND 
                            dataColumnA is null 
                         then ? 
                         else timeColumnA end ),
    dataColumnA = ( case when subjectColumnA is null AND 
                            timeColumnA is null AND 
                            dataColumnA is null 
                         then ? 
                         else dataColumnA end ),
    subjectColumnB = ( case when subjectColumnA is not null AND 
                            timeColumnA is not null AND 
                            dataColumnA is not null AND 
                            subjectColumnB is null AND 
                            timeColumnB is null AND 
                            dataColumnB is null 
                        then ? 
                        else subjectColumnB end ),
    timeColumnB = ( case when subjectColumnA is not null AND 
                            timeColumnA is not null AND 
                            dataColumnA is not null AND 
                            subjectColumnB is null AND 
                            timeColumnB is null AND 
                            dataColumnB is null 
                        then ? 
                        else timeColumnB end ),
    dataColumnB = ( case when subjectColumnA is not null AND 
                            timeColumnA is not null AND 
                            dataColumnA is not null AND 
                            subjectColumnB is null AND 
                            timeColumnB is null AND dataColumnB is null 
                        then ?
                        else dataColumnB end )
    

    Really, just add your criteria and if it’s not met, in your else, update back to itself.

    –EDIT

    Using your query above, you can still use CASE — works the same was as IIF:

    UPDATE table SET
        AAA3 = CASE WHEN AAA2 IS NOT NULL THEN 2 ELSE AAA3 END,
        BBB3 = CASE WHEN BBB2 IS NOT NULL THEN 2 ELSE BBB3 END,
        AAA2 = CASE WHEN AAA1 IS NOT NULL THEN 2 ELSE AAA2 END,
        BBB2 = CASE WHEN BBB1 IS NOT NULL THEN 2 ELSE BBB2 END,
        ...
    

    Good luck.

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

Sidebar

Related Questions

I'm using code from this answer: https://stackoverflow.com/a/6501353/494901 Basically when the timer ends, I want
From this question:- https://stackoverflow.com/questions/1342611/is-there-a-webservice-api-to-grab-a-screenshot-of-another-website and some other questions/google I got some results like:-- http://www.bitpixels.com/
I found this answer to this question https://stackoverflow.com/a/7244888/1473523 , but in my situation am
I want to continue on my previous question: https://stackoverflow.com/questions/3007168/torrents-can-i-protect-my-software-by-sending-wrong-bytes Developer Art suggested to add
I asked another question: https://stackoverflow.com/questions/1180240/best-way-to-sort-1m-records-in-python where I was trying to determine the best approach
I found this question https://stackoverflow.com/questions/4612563/get-push-notification-from-twitter-on-status-updates , but there was no answer. I'm looking to
Here is a quote from https://stackoverflow.com/users/893/greg-hewgill answer to Explain Python's slice notation . Python
Using the code from this answer: https://stackoverflow.com/a/9744961/514773 I've noticed that any time I enter:
From here: https://stackoverflow.com/a/5524120/462608 If you want to lock several mutex-protected objects from a set
From this answer https://stackoverflow.com/a/6457528/299110 I'm using ctrl.PreRender += (sender, e) => ControlPreRender(ctrl, rule); to

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.