Question

I have table store my answer and comment value. I need to get if it is null or answer value then combine. below query is not working. It's not getting any value from table.

SELECT DISTINCT 
       b.QM_ID,
       b.QM_QCM_ID,
       b.QM_Question,
       b.QM_Type,
       b.QM_Parent_Id,
       null,
       null 
  FROM question_master b 
       INNER JOIN Assessment_master d 
                  ON ((   d.AM_QM_ID = b.QM_Parent_Id 
                       OR d.AM_QM_ID = b.QM_ID) 
                      AND d.AM_HNM_ID = %d 
                      AND d.AM_HM_ID = %d 
                      AND d.AM_ASM_Local_Id = %@) 
 WHERE     b.QM_Parent_Id != 0 
       AND b.QM_Status = 'A' 
       AND b.QM_QCM_ID = %@ 
       AND b.QM_QRM_Id = %@ 
UNION 
SELECT DISTINCT 
       b.QM_ID,
       b.QM_QCM_ID,
       b.QM_Question,
       b.QM_Type,
       b.QM_Parent_Id,
       d.AM_Answer,
       d.AM_Comments 
  FROM question_master b 
       INNER JOIN Assessment_master d 
                  ON ((   d.AM_QM_ID = b.QM_Parent_Id 
                       OR d.AM_QM_ID = b.QM_ID) 
                      AND d.AM_HNM_ID = %d 
                      AND d.AM_HM_ID = %d 
                      AND d.AM_ASM_Local_Id = %@) 
 WHERE     b.QM_Parent_Id != 0 
       AND b.QM_Status = 'A' 
       AND b.QM_QCM_ID = %@ 
       AND b.QM_QRM_Id = %@

Question_Master:

QM_ID    QM_QRM_ID   QM_LCM_ID  QM_QCM_ID   QM_Question       QM_Parent_Id

432         5            19       1         question_parent       0
433         5            19       1         question_child        432
434         5            19       1           question_child1      432

Assessment_Master:

AM_ID     AM_UM_ID   AM_ASM_Local_Id  AM_QM_ID   AM_Answer   AM_Comments  AM_HNM_ID
1          8            1                433       NULL        testing      1

If i answer the child question 433 and i'm getting only parent with 433 child. I'm not getting 434 question.

a.QM_ID  a.QM_QCM_ID  a.QM_Question     a.QM_Parent_Id c.AM_Answer  c.AM_Comments
         432       1          question_parent     0                Null        NULL
          433      1          question_child       432             null        value

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top