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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:30:08+00:00 2026-05-20T15:30:08+00:00

hopefully somebody can help me with this query. I need to list all 200

  • 0

hopefully somebody can help me with this query. I need to list all 200 records from ngr_titles below, joined with their most recent related record from ngr_monitordata. The foreign key in ngr_monitordata is called titleid and the most recent should be the higher when_posted value for each title.
The problem is that ngr_monitordata contains millions of records and is increasing every second.

This is the query I used but it takes 14 seconds to execute:

SELECT * FROM ngr_titles
LEFT JOIN 
(SELECT titleid, MAX(when_posted) FROM ngr_monitordata GROUP BY titleid) tmp1
ON ngr_titles.id= tmp1.titleid;

What would be the best approach?

Tables are:

CREATE TABLE `ngr_titles` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) default NULL,
  `drop_min` int(11) NOT NULL default '50',
  `warn_pcnt` float(5,1) NOT NULL default '15.0',
  `crit_pcnt` float(5,1) NOT NULL default '25.0',
  `deviations` float(5,1) NOT NULL default '2.0',
  `addlobby` int(2) NOT NULL default '0',
  `url` varchar(255) default NULL,
  `graph_url` varchar(255) default NULL,
  `lastchecked` int(11) NOT NULL default '0',
  `last_exception` int(11) default NULL,
  `state` enum('ok','warning','critical') default NULL,
  `trend` int(11) NOT NULL default '0',
  `short_name` varchar(45) NOT NULL,
  `historical` varchar(45) NOT NULL,
  `cacti_url` varchar(255) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `title` (`title`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;



CREATE TABLE `ngr_monitordata` (
  `id` int(11) NOT NULL auto_increment,
  `titleid` int(11) default NULL,
  `when_posted` int(11) default NULL,
  `games_completed` int(11) default NULL,
  `games_created` int(11) default NULL,
  `games_in_progress` int(11) default NULL,
  `games_in_progress_gps` int(11) default NULL,
  `users_in_games` int(11) default NULL,
  `users_in_games_gps` int(11) default NULL,
  `users_in_lobby` int(11) default NULL,
  `users_in_passive` int(11) default NULL,
  `users_in_rooms` int(11) default NULL,
  `rooms` int(11) default NULL,
  `state` enum('ok','warning','critical','unknown') NOT NULL default 'ok',
  `user_drop` int(11) NOT NULL default '0',
  `retries` int(8) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `whowhenidx` (`titleid`,`when_posted`),
  KEY `whenidx` (`when_posted`),
  KEY `titleidx` (`titleid`),
  KEY `stateidx` (`state`)
) ENGINE=MyISAM AUTO_INCREMENT=120512615 DEFAULT CHARSET=utf8;
  • 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-20T15:30:08+00:00Added an answer on May 20, 2026 at 3:30 pm
    SELECT 
        t.*
    FROM 
        ngr_titles t 
    INNER JOIN 
    ngr_monitordata m
        ON 
    t.id = m.titleid 
        AND 
    m.when_posted = (SELECT MAX(when_posted) FROM ngr_monitordata WHERE titleid = t.id)
    

    Quick solution, it should work although I wrote it in haste. If it were me, I’d normalize the data slightly to reduce the overhead from aggregate function and subquery.

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

Sidebar

Related Questions

Hello stackoverflow friends! Hopefully somebody here can help me with this! I've looked all
Hopefully somebody can help me with this.. or at least point me in the
Hopefully somebody can help me out here. I'm working within an embedded ActionScript2 and
hopefully somebody can help The table structure is as follows: tblCompany: compID compName tblOffice:
Hopefully I can find some words of advice from somebody. Is it possible to
Greetings guys, hopefully somebody has fresher eyes and can help me pinpoint the problem
Hopefully I can explain this to where someone might understand it enough to help
This one is fairly complex, hopefully I can make this clear enough for somebody
Hopefully somebody can point me to something that could help. What I'm doing is
Hopefully can someone help me with an example, because I'm new in JSON: From

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.