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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:37:38+00:00 2026-06-06T12:37:38+00:00

A program I’ve been working on uses a complex MySQL query to combine information

  • 0

A program I’ve been working on uses a complex MySQL query to combine information from several tables that have matching item IDs. However, since I added the subqueries you see below, the query has gone from taking under 1 second to execute to over 3 seconds. Do you have any suggestions for what I might do to optimize this query to be faster? Am I wrong in my thinking that having one complex query is better than having 4 or 5 smaller queries?

    SELECT uninet_articles.*, 
           Unix_timestamp(uninet_articles.gmt), 
           uninet_comments.commentcount, 
           uninet_comments.lastposter, 
           Unix_timestamp(uninet_comments.maxgmt) 
    FROM   uninet_articles 
           RIGHT JOIN (SELECT aid, 
                              (SELECT poster 
                               FROM   uninet_comments AS a 
                               WHERE  b.aid = a.aid 
                               ORDER  BY gmt DESC 
                               LIMIT  1) AS lastposter, 
                              Count(*)   AS commentcount, 
                              Max(gmt)   AS maxgmt 
                       FROM   uninet_comments AS b 
                       GROUP  BY aid 
                       ORDER  BY maxgmt DESC 
                       LIMIT  10) AS uninet_comments 
                   ON uninet_articles.aid = uninet_comments.aid 
    LIMIT  10 
  • 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-06-06T12:37:39+00:00Added an answer on June 6, 2026 at 12:37 pm

    Queries can be though of as going through the data to find what matches. Sub-queries require going through the data many times in order to find which items are needed. In this case, you probably want to rewrite it as multiple queries. Many times, multiple simpler queries will be better – I think this is one of those cases.

    You can also look at if your indexes are working well – if you know what that is. The reason why has to do with this: How does database indexing work?.

    For a specific suggestion, you can find the last poster for each AID in a different query, and simply join it afterwards.

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

Sidebar

Related Questions

NOTE: program in java, server uses php, and mysql...file is .log or .txt file
My program is a game that uses RMI to allow users to connect to
I program in Java and have been trying to understand exactly what operator overloading
The program that I am working on takes a file and parses it line
/* Program that reads a sequence of words from keyboard and prints the list
The program that i'm developing uses a Microsoft access database, at the moment the
My program is now still running to import data from a log file into
Example program: list links This example program demonstrates how to fetch a page from
My program requires the result from inside an loop to be displayed or outputted
program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; var ints: array[1..2] of Integer =

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.