mysql - Problem with writing an SQL Sub Query -
I know that I should be missing something simple ... but I'm having trouble writing a SQL sub query . Looking at the following data
user_id question_id ANSWER_TEXT 89 1 value 1 89 2 value 2 80 2 value 2 99 2 value 2 96 1 value 1 96 2 value 2 111 1 value 1 111 2 value 2
<p> I have both question_id of user_id1 = 'VALUE1' and 2 = 'value2'
above the results The query is generating the question_id that needs to be received> User_answer`.user_id`, `User_answer`.question_id`,` User_ant`.`answer_text` Selection` `` user_answers` User_answer` where` User_answer`. In question_id` (1, 2) and `User_answer` in ('value1', 'value2') .`_txt`
but of course it Land that "value 1" but has a fully answer the question with a question with different answers 2 than 1 return value "2" (and vice versa).
I need to add in more circumstances but I think I can add that if I can at least do these two things.
One way to use self join is to use eg
Select as a1.user_id, ANSWER1, a2.answer_text as a1.answer_text user_answers as a1 a1.userid = a2.userid and a1.question_id = 1 and a2 as ANSWER2. Question_id = 2 where A1.answer_text to join user_answers a2
Sorry if the syntax is a bit far away (it's been a while since I was using MySQL), but you get this idea.
Comments
Post a Comment