Multiple rows of a join of two records

0

In a union of two tables where the main table is of type: Table A

A.row_Id, A.link_Id

and the secondary one is of the type: Table B

B.link_Id, B.Valor_a1, B.Valor_a2, B.Valor_b1, B.Valor_b2, B.Valor_c1, 
B.Valor_c2, B.Valor_d1, B.Valor_d2

I want to get a table with the non-null records

A.row_Id, B.Valor_a1, B.Valor_a2
A.row_Id, B.Valor_b1, B.Valor_b2
A.row_Id, B.Valor_c1, B.Valor_c2
A.row_Id, B.Valor_d1, B.Valor_d2

That is, from the second table I want to obtain up to four records (a, b, c, and d) that are not null, since there can only exist a / a and b / a, b and c / a, b, c and d)

I do not know how. Is it possible?
Thanks in advance

    
asked by Goyo 05.02.2018 в 17:31
source

1 answer

0

Please execute:

SELECT A.row_Id, B.Valor_a1 as valor_1, B.Valor_a2 as valor_2 FROM A JOIN B ON A.link_Id = B.link_Id 
UNION 
SELECT A.row_Id, B.Valor_b1 as valor_1, B.Valor_b2 as valor_2 FROM A JOIN B ON A.link_Id = B.link_Id
UNION 
SELECT A.row_Id, B.Valor_c1 as valor_1, B.Valor_c2 as valor_2 FROM A JOIN B ON A.link_Id = B.link_Id
UNION
SELECT A.row_Id, B.Valor_d1 as valor_1, B.Valor_d2 as valor_2 FROM A JOIN B ON A.link_Id = B.link_Id

You tell me how it went.

Greetings.

    
answered by 05.02.2018 / 17:43
source