splashz Posted August 20, 2010 Share Posted August 20, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/211288-joining-3-tables/ Share on other sites More sharing options...
kickstart Posted August 20, 2010 Share Posted August 20, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/211288-joining-3-tables/#findComment-1101679 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.