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 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
  • 1 View
  • 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

following the answers i got on this thread PHP MySQL Query to get most
The following question answers how to get large memory pages on Windows : how
I tried following the answer to this question , but could not get xsd.exe
I asked this goofy question earlier today and got good answers. I think what
I recently posted this question on the r-help mailing list but got no answers,
I'm trying to parse the following URI : http://translate.google.com/#zh-CN|en|你 but got this error message
After running the following lines : double d=Float.parseFloat(9.99); System.out.println(+d); I got this : 9.989999771118164
Lately I read this post: How do I use boost.lambda with boost.thread to get
In regards to my this question , I got this following answer to add
Can someone recommend a hosted solution that answers the following requirements (I have seen

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.