May 10, 2004 at 11:46 am
I have a 1-to-many relationship between my "Game" and "GameInfo" tables.
TABLE: Game
GameID, GameName
TABLE: GameInfo
GameInfoID, GameID, DateTimeOfThisPieceOfInfo, GameInfo
Let's assume that there are multiple records in GameInfo for GameID 1. I want to write a query that only returns the row of GameInfo where the "DateTimeOfThisPieceOfInfo" is the latest date. For clarity, here's how I would write the query to return multiple rows. Can someone help me write the query so it only returns the 1 row of GameInfo that has the latest date...
SELECT g.GameName, gi.GameInfo
FROM Game g
JOIN GameInfo gi
ON g.GameID = gi.GameID
WHERE g.GameID = 1
May 10, 2004 at 11:53 am
How about
SELECT TOP 1 g.GameName, gi.GameInfo
FROM Game G
INNER JOIN GameInfo gi
ON g.GameID = gi.GameID
WHERE g.GameID = 1
ORDER BY DateTimeOfThisPieceOfInfo DESC
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply