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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:42:23+00:00 2026-05-27T01:42:23+00:00

I’m a beginner to mysql. I have to fetch the most viewed contentid(for the

  • 0

I’m a beginner to mysql. I have to fetch the most viewed contentid(for the past 120 hours) from the table views. The views table contains 200,000 (lakh) records. I have indexed the contentid column, but my query takes upto 10 sec to fetch the result.

Views table structure is as follows:

contentid viewed                ip
155     2011-10-26 00:07:52     216.251.77.226
1150    2011-10-26 00:08:15     65.52.109.72
1134    2011-10-26 00:08:30     178.53.54.221
14      2011-10-26 00:08:49     178.53.54.221
693     2011-10-26 00:08:58     115.184.174.136
433     2011-10-26 00:09:14     66.249.71.138
558     2011-10-26 00:09:26     91.83.214.3
715     2011-10-26 00:16:01     128.171.36.161
226     2011-10-26 00:16:06     110.36.39.102
562     2011-10-26 00:16:51     84.3.173.188
1134    2011-10-26 00:16:53     110.39.67.139
198     2011-10-26 00:16:57     220.227.133.163
155     2011-10-27 05:43:59     64.135.215.142
155     2011-10-27 08:39:46     157.55.39.86
155     2011-10-27 11:23:05     99.55.166.146
155     2011-10-27 15:40:29     174.255.241.202
1150    2011-10-26 00:50:50     119.30.96.83
1150    2011-10-26 01:02:58     66.249.71.138
1150    2011-10-26 08:02:31     95.144.197.55
1132    2011-10-26 00:16:07     119.160.126.99

and my query is

SELECT contentid FROM views 
where viewed > DATE_SUB(NOW(), INTERVAL 120 HOUR) 
GROUP BY contentid ORDER BY count(contentid ) desc limit 0, 15
  • 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-27T01:42:24+00:00Added an answer on May 27, 2026 at 1:42 am

    I would think that nice indexes for this query would be either a simple index on viewed or a compound index on (contentid, viewed).


    You should also change the COUNT(contentid) to COUNT(*) :

    SELECT contentid FROM views 
    WHERE viewed > DATE_SUB(NOW(), INTERVAL 120 HOUR) 
    GROUP BY contentid 
    ORDER BY COUNT(*) DESC 
    LIMIT 0, 15
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a text area in my form which accepts all possible characters from
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.