I am trying to display the possible answers to a poll question When i use the following query i get 30 records back (when i expect 6 records) $query_getPoll = "SELECT *, pollQuestions.content as question, pollOptions.content as option FROM pollQuestions, pollOptions, pollVotes WHERE pollOptions.question_id = pollQuestions.question_id = pollVotes.question_id = '".$id_sent."' AND pollQuestions.displayed = '1' "; Code (markup): And when i group by question_id i get only 1 record back $query_getPoll = "SELECT *, pollQuestions.content as question, pollOptions.content as option FROM pollQuestions, pollOptions, pollVotes WHERE pollOptions.question_id = pollQuestions.question_id = pollVotes.question_id = '".$id_sent."' AND pollQuestions.displayed = '1' GROUP BY pollQuestions.question_id"; Code (markup): What am i overlooking?
select *, fields? that incorrect $query_getPoll = "SELECT pollQuestions.content as question, pollOptions.content as option FROM pollQuestions, pollOptions, pollVotes WHERE pollOptions.question_id = pollQuestions.question_id = pollVotes.question_id = '".$id_sent."' AND pollQuestions.displayed = '1' "; I dont know whats with pollQuestions.displayed = '1' but I would use LIMIT 1 instead
SELECT * -- whatever you want to get FROM pollOptions LEFT JOIN pollQuestions ON pollOptions.question_id = pollQuestions.question_id WHERE pollQuestions.question_id = '$id_sent' AND pollQuestions.displayed = '1' Code (markup): pollVotes doesn't seem to be required in the query.