How to combine between two datasets with a variable number of fields using SQL?

I have two query results from different tables, as shown below.

ID F1 F2 F3 ID F3 F4 F5
S1 d11 d12 d13 S2 d23 d24 d25
S2 d21 d22 d23 S3 d33 d34 d35
S3 d31 d32 d33 S4 d43 d44 d45

ID and F # are field names, the rest are values. I want to get a new result in a similar form from the above results.

ID F1 F2 F3 F4 F5
S1 d11 d12 d13
S2 d21 d22 d23
S2 d23 d24 d25
S3 d31 d32 d33
S3 d33 d34 d35
S4 d43 d44 d45

Is this possible in SQL? I am programming in VBA using ADO. I have never done such a task before.

, . , .

+3
2
select ID, F1, F2, F3, NULL as F4, NULL as F5
from Table1
union all
select ID, NULL as F1, NULL as F2, F3, F4, F5
from Table2
+7

, , , . , select * , .

select * from 
(select 1 as MY_ID, Table1.* from Table1) AS A
FULL OUTER JOIN
(select 2 as MY_ID, Table2.* from Table2) AS B
ON A.MY_ID = B.MY_ID
0

Source: https://habr.com/ru/post/1742122/


All Articles