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 6690957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:41:47+00:00 2026-05-26T05:41:47+00:00

I am using the following query to get the latest articles (article title +

  • 0

I am using the following query to get the latest articles (article title + author name + total comments) but it takes long time to run:

SELECT article.id, title, username, count( comment.id ) AS total_comments
FROM article
    LEFT JOIN COMMENT ON comment.article_id = article.id
    LEFT JOIN user ON article.user_id = user.id
WHERE STATUS = "open"
    AND section = "mobiles"
GROUP BY article.id
ORDER BY article.id DESC 
LIMIT 0 , 30

The output of explain is:

id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra
1   SIMPLE  article     ALL     status  NULL    NULL    NULL    77  Using where; Using temporary; Using filesort
1   SIMPLE  comment     ref     article_id  article_id  5   test.article.id     2    
1   SIMPLE  user    eq_ref  PRIMARY     PRIMARY     4   test.article.user_id    1

how to re-write the query to avoid creating temporary table?

Storage engine is MyISAM. Here is tables details with indexes:

article 
id, title,  body,   user_id,    status,     section
primary key: id
indexes: (user_i),(status,section,id)


comment
id, article_id, user_id,    body
primary key: id
index:(article_id)


user
id, username
primary key: id
  • 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-26T05:41:47+00:00Added an answer on May 26, 2026 at 5:41 am

    Would using a sub query instead of the grouped join speed up the process.

    SELECT article.id, title, username, 
          (
           select count(*) from COMMENT 
           where comment.article_id = article.id 
           ) AS total_comments 
    FROM article
        LEFT JOIN user ON article.user_id = user.id 
    WHERE STATUS = "open" 
        AND section = "mobiles" 
    ORDER BY article.id DESC  
    LIMIT 0 , 30 
    

    as per a previous question How to make a nested query?

    I hope this helps.

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

Sidebar

Related Questions

I get the session MaxInactiveInterval time using the following query. I am developing web
I am using the following query to select 1 random record - SELECT name
I am using the following query to get the count from multiple tables:- SELECT
I am using the following // perform query and get feed of all results
I am using the following query to get the transactions from a table made
I am using the following YQL query to get weather information http://query.yahooapis.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location%3D%2248907%22&format=json Is there
I want to get rows from database. I am using the following query: select
Am using the following query to get a Client. The Client has a public
While using the following query, I get the error #1054 - Unknown column 'plus'
Using the following query select * from table1 left join table2 on table1.name =

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.