Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving trouble forming SQL query
    primarykey
    data
    text
    <p>I have three tables. SurveyFact, Question, and Responses. The survey fact contains the data for surveys taken by clients while the Question and Responses table has the obvious data, a list of questions and possible responses per Question.</p> <p>SurveyFact:</p> <pre><code>| SurveyFactID | ClientID | QuestionID | ResponseCode | ------------------------------------------------------------ | 1 | 1 | 1 | 3 | | 2 | 1 | 2 | 3 | | 3 | 1 | 3 | 1 | </code></pre> <p>Question:</p> <pre><code>| QuestionID| QuestionText | ------------------------------------- | 1 | blah blah blah | | 2 | blah blah blah | | 3 | blah blah blah | </code></pre> <p>Response:</p> <pre><code>| ResponseID| QuestionID | ResponseCode |ResponseText | -----------------------------------------------------------| | 1 | 1 | 1 | like | | 2 | 1 | 2 | don't care | | 3 | 1 | 3 | hate | | 4 | 2 | 1 | like | | 5 | 2 | 2 | don't care | | 6 | 2 | 3 | hate | </code></pre> <p>Here is the query I've come up with. (That fails)</p> <pre><code>select sf.QuestionCode as [Question Number], q.QuestionText as [Question Text], r.ResponseText as [Reponse] from SurveyFact sf inner join Question q on q.QuestionID = sf.QuestionID inner join Responses r on r.ResponseCode = sf.ResponseCode where sf.ClientID = '1' and sf.QuestionID = q.QuestionID and sf.ResponseCode = r.ResponseCode </code></pre> <p>Even when I use select distinct it yields me the survey and questions with every possible answer instead just the the question/answer combo listed in SurveyFact. </p> <p>Help please?</p> <p>Requested Table: What I'm Seeing</p> <pre><code>| Question Number | Question Text |Response Text | ------------------------------------------------------ | 1 | blah blah blah | like | | 1 | blah blah blah | don't care | | 1 | blah blah blah | hate | | 2 | blah blah blah | like | | 2 | blah blah blah | don't care | | 2 | blah blah blah | hate | </code></pre> <p>What I want:</p> <pre><code>| Question Number | Question Text |Response Text | ------------------------------------------------------ | 1 | blah blah blah | don't care | | 2 | blah blah blah | like | </code></pre> <p>First one is Number, QUestion, Then every possible answer. Second is just Number,Question, just chosen answer</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload