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

  • Home
  • SEARCH
  • 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 225455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:24:55+00:00 2026-05-11T19:24:55+00:00

I got a query: SELECT a.nick,grp,count(*) FROM help_mails h JOIN accounts a ON h.helper=a.id

  • 0

I got a query:

SELECT a.nick,grp,count(*) FROM help_mails h JOIN accounts a ON h.helper=a.id WHERE closed=1 GROUP BY helper, grp, a.nick

What is wrong with this join?
When I made 2 queries:

SELECT helper,grp,count(*) FROM help_mails h WHERE closed=1 GROUP BY helper, grp;
SELECT nick FROM accounts WHERE id IN (...)

It is 100 times faster.

EXPLAIN returns this:

id     select_type     table   type    possible_keys   key     key_len     ref     rows    Extra
1   SIMPLE  h   ref     closed  closed  1   const   1846    Using temporary; Using filesort
1   SIMPLE  a   ref     PRIMARY     PRIMARY     4   margonem.h.helper   1   Using where; Using index

accounts.id, help_mails.grp and help_mails.closed got indexes.

  • 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-11T19:24:55+00:00Added an answer on May 11, 2026 at 7:24 pm

    Note that your first query is not same as the second ones.

    If you have same NICK for two account‘s, COUNT(*)‘s for these accounts will be merged together in the first query and returned separately in the second one.

    If you want separate COUNT‘s for separate account‘s to be always returned, you may combine your queries into one:

    SELECT  a.nick, gpr, cnt
    FROM    (
            SELECT  helper, grp, COUNT(*) AS cnt
            FROM    help_mails h
            WHERE   closed = 1
            GROUP BY
                    helper, grp
            ) ho
    JOIN    accounts a
    ON      a.id = ho.helper
    

    or change a GROUP BY condition for the first query:

    SELECT  a.nick, grp, count(*)
    FROM    help_mails h
    JOIN    accounts a
    ON      h.helper = a.id
    WHERE   closed = 1
    GROUP BY
            helper, grp, a.id, a.nick
    

    Building a composite index on help_mails (closed, helper, grp) will help you a lot, since it will be used in GROUP BY.

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

Sidebar

Related Questions

I've got this query: SELECT PICTURE FROM LOGO WHERE LOGONO = ? (PICTURE is
Say I've got a query SELECT TOP 10 ... FROM ... ORDER BY ...
i've got this union query: (SELECT INSTALLER, INSTALLTIME, RESULT, JOBNUMBER, HONAME, ADDRESS, CITY, STATE,
I have this query: $this->set('grades', $this->Grade->Query( SELECT AVG(grade), sections.section_name FROM grades, sections WHERE sections.id
I've got an SQL query that looks like this: INSERT INTO DB..incident ( incident_number
I've got a reasonably simple query (this time) that I need ALL the results
In a request to YQL (select * from html where url=...) I got the
What is wrong with this code ? I got this exception on the last
I've got a query that returns the cost of wages for a given member
I've got the following query to determine how many votes a story has received:

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.