BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to retrieve latest detail entry from a master/detail rel

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
davout
Guest





PostPosted: Wed Aug 25, 2004 10:04 am    Post subject: How to retrieve latest detail entry from a master/detail rel Reply with quote




I'm using MySQL 4.0.16

How do I join two tables - one a master table, the second a detail table holding multiple status entries for each master table entry - so that a query can return the master table fields plus the latest status fields (the status entry with the most recent date)?

table : station
Fields: StationID INTEGER, StationName VARCHAR

e.g.
1, London
2 ,Brighton

table: stationstatus
Fields: StationID, StatusDate, Metric1,Metric2,Metric3

e.g.

1, 23/8/04, 1, 1, 1
1, 24/8/04, 2, 2, 2
1, 25/8/04, 3, 3, 3
2, 23/8/04, 4, 4, 4
2, 24/8/04, 5, 5, 5
2, 25/8/04, 6, 6, 6

What I'm looking for is a query that returns

StationID,StationName,StatusDate,Metric1,Metric2,Metric3

e.g.

1, London, 3, 3, 3,
2, Brighton, 6, 6, 6

Any ideas?

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.