Is it possible to create a select statement with the result of another select statement?
Important is, that Table2 can have a different number of columns.
Example:
Table1:
+------+------+
| colA | colB |
+------+------+
| colE | 0 |
| colF | 0 |
+--------+----+
Table2:
+------+------+------+
| colE | colF | colG |
+------+------+------+
| 1 | 1 | 1 |
| 1 | 1 | 1 |
+------+------+------+
select colA from Table1 where colB = '0';
Result:
colE
colF
and now I want to sum all values of the columns in Table2 where the column names are the same as in the result above (sum of all values of colE and colF). The result should be 4 in this case.
I use mariaDB.