Replaced the last "and" with "having". Result:
| submissionid | num_results | num_voters |
+--------------+-------------+------------+
| 479 | 18 | 17 |
| 500 | 13 | 12 |
| 658 | 70 | 71 |
| 966 | 24 | 23 |
Hmh. Thanks Tub.
Oh well. This requires another fixing program then. Anyone want to contribute? :) The database description is as follows:
CREATE TABLE vote_desc (
vote_id MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
topic_id MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0, KEY t(topic_id),
vote_text TEXT NOT NULL,
vote_start INT NOT NULL DEFAULT 0,
vote_length INT NOT NULL DEFAULT 0
); -- Note: One of these per each submission. --
CREATE TABLE vote_voters (
vote_id MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0,
FOREIGN KEY(vote_id)REFERENCES vote_desc(vote_id),
vote_user_id MEDIUMINT(8) NOT NULL DEFAULT 0, KEY u(vote_user_id),
vote_user_ip CHAR(8) NOT NULL DEFAULT '', KEY i(vote_user_ip),
vote_opt_id TINYINT(4) UNSIGNED NOT NULL DEFAULT 0, -- refers to vote_results.vote_option_id --
PRIMARY KEY(vote_id,vote_user_id)
); -- Note: One of these per each vote. --
CREATE TABLE vote_results (
vote_id MEDIUMINT(8) UNSIGNED NOT NULL DEFAULT 0,
FOREIGN KEY(vote_id)REFERENCES vote_desc(vote_id),
vote_option_id TINYINT(4) UNSIGNED NOT NULL DEFAULT 0, KEY o(vote_option_id),
vote_option_text VARCHAR(255) NOT NULL DEFAULT '', KEY t(vote_option_TEXT(1)),
vote_result INT NOT NULL DEFAULT 0,
PRIMARY KEY(vote_id,vote_option_id)
-- Note: vote_result should match count(vote_user_id) where vote_opt_id=vote_option_id and vote_id=vote_id --
); -- Note: One of these per each poll option in each submission. --