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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:31:24+00:00 2026-06-06T18:31:24+00:00

I have two tables described below. What I need is a single query that

  • 0

I have two tables described below. What I need is a single query that will tell me the players whose score hasn’t changed in a given number of days.

CREATE TABLE players (
  pid INT(50),
  name VARCHAR(255),
  updatedAt DATETIME
);

CREATE TABLE pl_scores (
  pid INT(50),
  score INT(255),
  updatedAt DATETIME
);

The players table keeps a master list of all players along with other non-changing data not shown here for the sake of brevity. The pl_scores table keeps a running history of score changes in order to track growth and other values that might change. A new record is inserted into pl_scores for each player every 6 hours.

What I would like to get is the pid of the players that haven’t had a change of score in a certain number of days, but I am unsure of how to group that in order to get the correct values.

Example dataset

(only shows last score of each day which is only one needing to be compared really)

+------+------+-------+------+---------+---------------------+
| pid  | aid  | score | rank | cityCnt | updatedAt           |
+------+------+-------+------+---------+---------------------+
| 1660 |    0 |   801 | 2111 |       1 | 2012-06-20 22:14:11 |
| 1660 |    0 |   801 | 2250 |       1 | 2012-06-21 22:15:45 |
| 1660 |    0 |   801 | 2387 |       1 | 2012-06-22 22:17:06 |
| 1660 |    0 |   801 | 2547 |       1 | 2012-06-23 22:17:09 |
| 1660 |    0 |   801 | 2702 |       1 | 2012-06-24 22:19:50 |
| 1660 |    0 |   801 | 2836 |       1 | 2012-06-25 22:21:07 |
| 1660 |    0 |   801 | 2956 |       1 | 2012-06-26 21:42:44 |
+------+------+-------+------+---------+---------------------+

EDIT

The answer found below worked perfectly, but now I’d like to take it a step further and limit the results by a hardcoded value found in a 3rd table. Here is the working SQL statement

SELECT a.pid, c.aid, b.name AS pName, c.name AS aName, a.score FROM pl_scores AS a 
JOIN players AS b ON a.pid = b.pid 
JOIN alliances AS c ON b.aid = c.aid 
WHERE a.updatedAt >= CURRENT_DATE() - INTERVAL 3 DAY GROUP BY a.pid HAVING MIN(a.score) = MAX(a.score);

Each player has multiple cities throughout the world. I’d like to limit the results by players with cities found on a given continent. For example, I want to find every player that hasn’t changed their score in the last 3 days on continent 34. The cities table looks like this:

CREATE TABLE cities (
  cid INT(50),
  pid INT(50),
  name VARCHAR(255),
  cont INT(10),
  updatedAt DATETIME
);
  • 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-06T18:31:26+00:00Added an answer on June 6, 2026 at 6:31 pm

    You could get pids of players with their scores unchanged like this:

    SELECT pid
    FROM pl_scores
    WHERE updatedAt >= CURRENT_DATE() - INTERVAL n DAY
    GROUP BY pid
    HAVING MIN(score) = MAX(score)
    

    Now you can use those pids to get full (or just more) information about the corresponding players, i.e. like this:

    SELECT *  /* or you could specify the necessary columns here */
    FROM players
    WHERE pid IN (  
      SELECT pid
      FROM pl_scores
      WHERE updatedAt >= CURRENT_DATE() - INTERVAL n DAY
      GROUP BY pid
      HAVING MIN(score) = MAX(score)
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables in a legacy database that I need to map using
I have two tables : teachers (teacher_id,teacher_name) courses (teacher_id,course_id) And I need to display
I have two tables, the first has a primary key that is an identity,
I have two tables: a schedule table that contains information about how an employee
I have two simple tables as described here... Table = Person PersonID (int, PrimaryKey)
i have two tables: 1) Users 2) Scenarios Relation between them can be described
I have an entity that is made up of properties from two different tables
Suppose we have 4 tables as described below: Table 1: Element element_id [integer] (PK)
I have a two mysql tables that I want to merge together in one
I have two tables that have a foreign key constraint between them Table event

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.