Mar 20 2023 08:45 AM - edited Mar 20 2023 08:50 AM
Table1 | |||
code | description | ||
A000 | fever | ||
A001 | stomach virus | ||
Table2 | |||
MEMBER_NBR | code1 | code2 | |
12368 | A000 | NULL | |
2476 | NULL | A001 | |
|
I need to join these 2 tables. the final result will be in the form of
Result table | |||
Code1 | description1 | code2 | description2 |
A000 | fever | NULL | null |
NULL | null | A001 | stomach virus |
Mar 20 2023 09:33 PM - edited Mar 20 2023 09:34 PM
We cannot run a query on the text in your question. What we need is a table with some data. So let's divide the work between us, You will provide what you can and we will fill the blank :)
please post:
1) Queries to CREATE your table(s) including indexes
2) Queries to INSERT sample data.
3) The desired result given the sample, as text or image of excel for example.
4) A short description of the business rules, and how you got 1-2 of the results
5) Which version of SQL Server you are using (this will help to fit the query to your version).
Note: This is something you should always provide when you have questions related to queries.
Regards,
Mar 20 2023 11:52 PM
@Trisha_Ravindra , your table(s) design is a bit strange. Anyway, this should give you the wanted result:
SELECT *
FROM Table2 AS T2
LEFT JOIN
Table1 AS C1
ON T2.code1 = C1.code
LEFT JOIN
Table1 AS C2
ON T2.code2 = C2.code