# Poll results

**URL:** https://meta.discourse.org/t/poll-results/275147
**Category:** Data & reporting
**Tags:** polls, sql-query
**Created:** [December 19, 2018, 10:56am UTC](https://meta.discourse.org/t/poll-results/275147 "2018-12-19T10:56:49Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![JanJoost](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/janjoost/32/97173_2.png) [@JanJoost](https://meta.discourse.org/u/JanJoost)
#### Post date: [December 19, 2018, 10:56am UTC](https://meta.discourse.org/t/poll-results/275147/1 "2018-12-19T10:56:49Z")

</div>

Hi all,

I just wrote a post here on how our users mis-use (abuse?) the poll-feature to create their own pub quiz.

> [@Poll: Export poll results in CSV for quiz creator?](https://meta.discourse.org/t/poll-export-poll-results-in-csv-for-poll-creator/94265/5):
>
> Hi there! The new poll implementation changed stuff a bit, so I had to figure out how to get this sorted. Please note that we’re sort of mis-using the poll-feature to build a quiz. That also means that we’re not really using the poll to identify the correct answer - all we want is an overview of the voting results, so we can export those to CSV and do some further manual processing to see who actually won the quiz. Some assumptions: I know nothing about SQL. My querie can probably be optimi…

I created a small query that gets the results of a post with N polls, including which user voted for which poll option.

This is that query, perhaps it’s useful for others as well. Please note that the link contains more information on how we set up the quiz and how we get the results.

```
-- [params]
-- int :topic_id
-- int :post_number

SELECT polls.name AS "Poll name", poll_options.html AS "Answer", poll_votes.user_id AS "User ID", users.username AS "Username"
	FROM poll_options
	INNER JOIN poll_votes ON poll_options.id=poll_votes.poll_option_id
	INNER JOIN polls ON polls.id=poll_votes.poll_id
	INNER JOIN users ON users.id=poll_votes.user_id
	WHERE poll_options.id IN (
		SELECT id FROM poll_options WHERE poll_options.poll_id IN (
			SELECT id FROM polls WHERE post_id IN (
				SELECT id FROM posts WHERE topic_id=:topic_id AND post_number=:post_number ) 
			)
		)
	ORDER BY polls.name, html

```
