Very Recently i faced one Problem, struggled a lot to Find Solution, but didn't find that solution yet. So trying to share that Problem with you all.
Consider there are two tables. Table 1 and Table 2.
Table 1 Contain Following Details
Question_Id | Question |
1 | Question1 |
2 | Question2 |
3 | Question3 |
4 | Question4 |
Table 2 Contain Following Details
Question_Id | Option_Id | Options |
1 | 11 | Q1Option1 |
1 | 12 | Q1Option2 |
1 | 13 | Q1Option3 |
1 | 14 | Q1Option4 |
2 | 21 | Q2Option1 |
2 | 22 | Q2Option2 |
2 | 23 | Q2Option3 |
2 | 24 | Q2Option4 |
3 | 31 | Q3Option1 |
3 | 32 | Q3Option2 |
3 | 33 | Q3Option3 |
3 | 34 | Q3Option4 |
3 | 35 | Q3Option5 |
3 | 36 | Q3Option6 |
4 | 41 | Q4Option1 |
4 | 42 | Q4Option2 |
4 | 43 | Q4Option3 |
4 | 44 | Q4Option4 |
4 | 45 | Q4Option5 |
Now we have to write a Query that should return a Table in a Below Stated format.
ID | QuestionOption |
1 | Question1 |
11 | Q1Option1 |
12 | Q1Option2 |
13 | Q1Option3 |
14 | Q1Option4 |
2 | Question2 |
21 | Q2Option1 |
22 | Q2Option2 |
23 | Q2Option3 |
24 | Q2Option4 |
3 | Question3 |
31 | Q3Option1 |
32 | Q3Option2 |
33 | Q3Option3 |
34 | Q3Option4 |
35 | Q3Option5 |
36 | Q3Option6 |
4 | Question4 |
41 | Q4Option1 |
42 | Q4Option2 |
43 | Q4Option3 |
44 | Q4Option4 |
45 | Q4Option5 |
Condition:
Never use UNION and LOOP
Thank you
0 comments:
Post a Comment