I have two tables:
Table 1:
ID NAME
1 ID1
2 ID2
3 ID3
4 ID4
5 ID5
6 ID6
7 ID7
Table 2:
Parent_ID Child_ID
1 2
2 5
2 3
3 6
How do I write a query to get below output if I assign Parent_Id = 1 in where condition?
P_ID NAME Is_Group Selected
1 ID1 Yes No
2 ID2 Yes Yes
3 ID3 Yes Yes
4 ID4 No No
5 ID5 No Yes
6 ID6 No Yes
7 ID7 No No
So, output mainly contains records from table one but also it need to have two additional columns.
Value in Is_Group column should be "Yes" if ID from Table 1 exists in Parent_ID column in Table 2. Value in Selected column should be "yes" if ID from Table 1 exists in Child_ID column in Table 2 and Parent_ID = 1 (like a cross reference).
In additional, I need to check if a Child_ID has any cross reference. For example In Table 2 Child_ID is 2 for Parent_Id 1, 2 also has 5 and 3 as child_Id so I need to have Selected column values as "Yes" for Id's 3 and 5 and so on.
Thanks in advance for your reply. Sorry for my English.