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 );