Hi All,
I am doing a select statement with 4 joins (LEFT), to produce a list of questions stored in the database. I want to list these by their Section in order to populate a form.
For instance i have Section 1, question 1 = What is your name... etc.
I am using order by Section, Question to try and achieve this but it does not seem to produce the desired result.
I get the Sections in order, but then i get the questions ordered as 1, 10, 20, 30, 2, 3 rather than the order within the section.
I think this is fairly straightforward order requirement, so maybe there is something i have missed.
Any advice appreciated!
Here is my full query..
I am doing a select statement with 4 joins (LEFT), to produce a list of questions stored in the database. I want to list these by their Section in order to populate a form.
For instance i have Section 1, question 1 = What is your name... etc.
I am using order by Section, Question to try and achieve this but it does not seem to produce the desired result.
I get the Sections in order, but then i get the questions ordered as 1, 10, 20, 30, 2, 3 rather than the order within the section.
I think this is fairly straightforward order requirement, so maybe there is something i have missed.
Any advice appreciated!
Here is my full query..
Code:
SELECT
Qmaster.id as QuestionnaireID,
Qmaster.Questionnaire,
Qmaster.QuestionnaireText,
S.id as SectionID,
S.sectionNumber,
S.sectionName,
S.sectionText,
Q.Question,
Q.Number,
Q.id_QuestionType,
Q.ShowOnWeb,
Q.Required,
Q.id_AnswersGroup,
Q.id as QuestionID,
A.Answers
FROM Questionnaire Qmaster
JOIN Section S ON S.id_Questionnaire = Qmaster.id
JOIN Question Q ON S.id = Q.id_Section
LEFT JOIN QuestionType Qt ON Qt.id = Q.id_QuestionType
LEFT JOIN AnswerGroup A ON Q.id_AnswersGroup = A.id
WHERE Qmaster.id = '1' ORDER BY SectionCount, Q.Number