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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:45:44+00:00 2026-05-28T01:45:44+00:00

I have a simple database that keeps track of transactions from multiple players in

  • 0

I have a simple database that keeps track of transactions from multiple players in a game.

When a game is started between two players, a unique game_id is generated and stored in a separate database called game_ids. In the database I am querying (game_transactions) I need the following to happen…

Table game_transactions sample data:

game_id | home_id | visiting_id | timestamp | ...
   3         1           2        00000001
   4         1           3        00000001
   3         2           1        00000002
   3         1           2        00000003
   4         1           3        00000002
   3         2           1        00000004
   4         1           3        00000003

As you can see, when one player completes a turn their game is added to this table. This goes on until the game is completed. What I am trying to do is get all rows when searching by the user_id “WHERE home_id = user_id OR visiting_id = user_id”. However this returns ALL the rows for that specific user, I want to limit the query to give the row of data for the MOST RECENT game_id by the given timestamp. The timestamp is an actual UNIX time stamp, but for example purposes this is more readable.

When said and done, this query needs to return the following when user_id = 1:

game_id | home_id | visiting_id | timestamp | ...
   3         2           1        00000004
   4         1           3        00000003

Please let me know if I need to clarify further.

Thank you.

On a side note, I will be purging the database of entries older than x days. But this will be a cron that runs once a day, trying to keep queries to a minimum!

  • 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-28T01:45:45+00:00Added an answer on May 28, 2026 at 1:45 am
    SELECT gt.game_id, gt.home_id, gt.visiting_id, gt.timestamp
       FROM game_transactions gt
           INNER JOIN (SELECT game_id, MAX(timestamp) AS MaxTimestamp
                           FROM game_transactions
                           WHERE 1 IN (home_id, visiting_id)
                           GROUP BY game_id) q
               ON gt.game_id = q.game_id
                   AND gt.timestamp = q.MaxTimestamp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two simple tables in my database. A card table that contains Id,
We have a database that is backed up weekly in simple mode. Yesterday, we
I have a simple UserControl for database paging, that uses a controller to perform
I have a simple app that uses an SQL Express 2005 database. When the
I have a simple web service that uses an oracle database. When I test
I have created a simple windows service that periodically checks a remote database via
I have a simple database with two tables. Users and Configurations. A user has
I have a simple database with multiple tables. I can't figure out how to
I have a database that I need to connect to and select from. I
I have several sql queries that I simply want to fire at the database.

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.