Hi all,I'm stuck on a SQL query that I've trying to get my head round. I'm pretty sure that I've gone a way off course with it and was hoping someone would be able to help.I have three tables (with example data)surveyQuestions
surveyMulti- this table is only used when the answerTypeID=4, with 1 being a yes/no answer and 2 being a sliding scale answer 1/2/3/4/5
surveyAnswers
I'm trying to get a query to give results like:=========Results Start=========Do you have a favorite colour?Yes 2No 0Pick your two favorite colours?Yellow 0Red 2Green 1Other 1=========Results End=========My query so far looks like thisSELECT DISTINCT(SQ.question) , SQ.questionID , SQ.priority , SM.answer , min(SA.answer) as thisAnswer , COUNT(SA.answer) as theAnswer FROM (( surveyQuestions as SQLEFT JOIN surveyMulti as SM ON SQ.questionID = SM.questionID )LEFT JOIN surveyAnswers as SA ON SQ.questionID = SA.questionID ) WHERE SQ.active = '1' AND SM.active = '1' AND SA.active = '1' GROUP BY SQ.question , SQ.questionID , SQ.priority , SM.answer , SA.answerORDER BY SQ.priority , SM.answer
So I guess my first question is can the above result be created from the one query? Next, if it can, where am I going wrong?I know there is quite a bit missing on this query and that I'm in over my head, so thanks in advance for any help,Richard