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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:20:59+00:00 2026-05-18T20:20:59+00:00

following the answers i got on this thread PHP MySQL Query to get most

  • 0

following the answers i got on this thread PHP MySQL Query to get most popular from two different tables

ive timed the query and im getting disturbing times when calling this query. I get over 8 seconds. afrostarvideos table has about 2000 records,afrostarprofiles about 300records. even after limiting the query to only five. goto http://www.veepiz.com/index.php and check this generation time under popular artists. Please help optimize this query

//Get current time 
    $mtime = microtime(); 
//Split seconds and microseconds 
    $mtime = explode(" ",$mtime); 
//Create one value for start time 
    $mtime = $mtime[1] + $mtime[0]; 
//Write start time into a variable 
    $tstart = $mtime;        
        $q= "SELECT `p`.*, SUM(`v`.`views`)+`p`.`views` AS `totalViews` FROM `afrostarprofiles` `p` LEFT OUTER JOIN `afrostarvideos` `v` ON `p`.`id` = `v`.`artistid`".
            "GROUP BY `p`.`id` ORDER BY SUM(`v`.`views`)+`p`.`views` DESC LIMIT $pas_start,$end";        
        $r=mysql_query($q);
//Get current time as we did at start 
    $mtime = microtime(); 
    $mtime = explode(" ",$mtime); 
    $mtime = $mtime[1] + $mtime[0]; 
//Store end time in a variable 
    $tend = $mtime; 
//Calculate the difference 
    $totaltime = ($tend - $tstart); 
//Output result 
    printf ("Page was generated in %f seconds !", $totaltime);
  • 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-18T20:21:00+00:00Added an answer on May 18, 2026 at 8:21 pm

    First thing to know – as soon as you have an ORDER BY, the LIMIT doesn’t help you.

    Once MySQL realizes that it needs to order the results before it can limit them, it has to go through the entire table to get all the results before it orders them (and then limits them) for you.

    That said (and without seeing the EXPLAIN for your query [which would be useful]), I’m guessing that most of the time is taken by that LEFT JOIN.

    Make sure that there is an index on afrostarprofiles.id (I’m guessing it’s the primary key, so you’re good) and afrostarvideos.artistid.

    Also, unless you want to get a result even when there are no matching artists in your second join, I would recommend trying a JOIN (otherwise known as an INNER JOIN) instead of a LEFT JOIN.

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

Sidebar

Related Questions

The following question answers how to get large memory pages on Windows : how
In regards to my this question , I got this following answer to add
EDIT: minor fixes (virtual Print; return mpInstance) following remarks in the answers. I am
How do you answer the following questions from managers, testers and other people in
I'm following along with this useful looking answer to my question . It seems
NOTE: XMLIgnore is NOT the answer! OK, so following on from my question on
Following on from my recent question on Large, Complex Objects as a Web Service
Following this question: Good crash reporting library in c# Is there any library like
I currently have a thread that listens for data from the network and then
This question made me question a practice I had been following for years. For

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.