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
https://forums.phpfreaks.com/topic/211288-joining-3-tables/
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
https://forums.phpfreaks.com/topic/211288-joining-3-tables/#findComment-1101679
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.