Hi
Based on the below tables
Table_A
Id RelatedId
---------------
1 1
1 2
1 3
2 4
2 5
2 2
3 7
3 8
4 9
Table_B
RelatedId Name
--------------
2 A
3 B
I want to get all the rows from Table_A which have atleast one matching relatedid in Table_B. The Ids from Table_A that do not have match in Table_B will have single row in the result table.
So output (result table) in this case will be
Id RelatedId
---------------
1 1
1 2
1 3
2 4
2 5
2 2
3 Null
4 Null
Thanks
EDIT: Seems like the question text is confusing for many. So a detailed explanation:
Table_A Id 1 has both 2 and 3 (Related Ids) matching in table_B. So output will have all the rows for 1 from Table_A. Similary Id 2 from Table_A has 2 (Related Id) matching in table_B. So all rows corresponding to 2 from Table_A will be picked up. Since 3 does not have any matching relatedid in table_B it will be displayed but with NULL as relatedid in the results table.