Export a list of User Emails by User_ID

Yeah, I thought of that too. The initial query was all I needed to resolve this issue, but having emails returned in the poll results query will be useful for the future.

I went ahead and had the AI do as you suggested. With a little fiddling (to make the specific poll selectable), I got the following:

-- [params]
-- int :topic_id
-- int :post_number
-- text :poll_name

SELECT polls.name AS "Poll Name",
       poll_options.html AS "Answer",
       poll_votes.user_id AS "User ID",
       users.username AS "Username",
       user_emails.email AS "Email"
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
LEFT JOIN user_emails ON users.id = user_emails.user_id AND user_emails.primary
WHERE poll_options.poll_id IN (
    SELECT polls.id FROM polls
    WHERE polls.post_id = (
      SELECT posts.id FROM posts WHERE topic_id = :topic_id AND post_number = :post_number
    ) AND polls.name = :poll_name
)
ORDER BY polls.name, poll_options.html

Seems like it’s working, thanks again for the advice!