Long story short, what fields should I put after the GROUP BY clause ?
SELECT questions.question_id, questions.title, questions.content, questions.view_count, questions.posted_on, users.user_id, users.group_id, users.username, users.first_name, users.last_name COUNT(answers.answer_id) AS answer_count
FROM (questions)
JOIN answers ON questions.question_id = answers.question_id
JOIN users ON questions.user_id = users.user_id
WHERE `questions`.`publish` = 'Y' AND `questions`.`deleted_at` IS NULL AND `users`.`blocked` = 'N'
GROUP BY questions.question_id
should I put every non-aggregated fields mentioned in the SELECT, or just one of them is fine ? (eg. just question_id) I am confused because in either way, the results are the same. What is the difference ?
Tutorials out there on the web all seems to give an example of using just two fields, one aggregated field and one normal field.
update: ok, it looks like I have to put all of them to get an accurate result. That brought up other questions: How accurate is accurate ? Wouldn't one do just fine ? How about the impact on performance ?