Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 284773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:29:13+00:00 2026-05-12T05:29:13+00:00

Long story short, what fields should I put after the GROUP BY clause ?

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:29:13+00:00Added an answer on May 12, 2026 at 5:29 am

    “You need to put all the non-agregated columns for accurate result”

    True, but I would add that your put all the columns, in the order you want it to be grouped ( which could be important for you ?).

    Edit : Accurate means that if you dont do so, your query will just crash. About performances, the more fields there is in your GROUP BY, the more your performances decrease, but it’s not really a surprise

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long story short, I have a substantial Python application that, among other things, does
Long story short, we found files promoting prescription drugs on our server that we
Long story short, I have an ASP.NET application I'm trying to debug and at
Long story short, I'm developing a theme template for a blog that enables you
Long story short, the database I'm using needs to get looked at. Until that
Long story short is I tried to quickly update a single row in SQL
Long story short, I'm making a custom Swing component that's basically a JTable with
Long story short, client's hosting is using php 5.2.5 and i desperately need to
Summary Long story short, we've been tasked with gutting the authentication and authorization parts
To make a long story short I have to use processing in a class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.