Jump to content

Joining 3 tables


splashz

Recommended Posts

I have 3 tables, league, game, and line. For the sake of this post, lets say the tables are structured as follows.

league

idleague, leaguename, misc league info

 

game

idgame, idleague, misc game info

 

line

timestamp, idgame, misc line info

 

I have a script that inserts data into the database every minute or so and uses the timestamp field. I want a select statement that will get the rows from the most recent timestamp, and trace back to the league table and return the leaguename of the leagues that were updated. Does that make sense? It sounds confusing even as I write it.

Link to comment
Share on other sites

Hi

 

Something like this

 

SELECT a.leaguename
FROM league a
INNER JOIN  game b ON a.idleague = b.idleague
INNER JOIN line c ON b.idgame = c.idgame
INNER JOIN (SELECT MAX(timestamp) AS latesttimestamp FROM line) d ON c.timestamp = d.latesttimestamp

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.