I have two table, in SQL; the first table(T1) is this:
ID
----
401
402
403
634
635
636
The second table(T2) is this:
ID1 | VALUE1 | ID2 | VALUE2
---- -------- ----- -------
401 | TEST | 634 | SAMPLE1
402 | MYVAL | 635 | TRUE
The result i need is this:
T1.ID | T2.ID1| T2.VALUE1 | T2.ID2 | T2.VALUE2
------ ------- ----------- -------- ----------
401 | 401 | TEST | 634 | SAMPLE1
402 | 402 | MYVAL | 635 | TRUE
634 | 401 | TEST | 634 | SAMPLE1
635 | 402 | MYVAL | 635 | TRUE
The value 403 and 636 of T1 must not be present in the result because don't have any reference in T2.
There is a way to accomplish this with some INNER JOIN? I'm using MS SQL Server 2017.
Suppose you can do simple join tables like this:
select t1.id, t2.id1, t2.value1, t2.id2, t2.value2
from t1
join t2 on (t1.id = t2.id1 or t1.id = t2.id2)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments