Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
pithhelmet
Posting Yak Master
183 Posts |
Posted - 2004-08-27 : 16:04:17
|
| Hi Everyone -I have inherited an application that logsGPS coordinates form multiple laptop units.All this data is being written to a single database table.there is an autoincrement field, along with theIP of the incoming packet.What i need to do is get the latest recordfor each of the unique IP addresses.the table name isgps_historythe autoincrement field name is history_idand the IP field name issender_ipplease advise on a fast SQL query to get the last record for each unique IP address.thankstony |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-08-27 : 16:12:57
|
| I think this is what you need:SELECT sender_ip, MAX(history_id)FROM gps_historyGROUP BY sender_ipTara |
 |
|
|
pithhelmet
Posting Yak Master
183 Posts |
Posted - 2004-08-27 : 16:22:08
|
| Tara -again you have saved my bacon!!thanks a million!!!take caretony |
 |
|
|
pithhelmet
Posting Yak Master
183 Posts |
Posted - 2004-08-27 : 16:31:14
|
| Tara and all -Thanks for the reply - it works great -now a similar problem....I would like to get all the fields associated with the record that is returned inthe query above...how can i accomplish that???thanks againtake caretony |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-08-27 : 16:34:46
|
| SELECT gh.sender_ip, t.LastOne, gh.SOmeColumnName, ...FROM gps_history ghINNER JOIN (SELECT sender_ip, MAX(history_id) AS LastOneFROM gps_historyGROUP BY sender_ip) tON gh.sender_ip = t.sender_ipTara |
 |
|
|
pithhelmet
Posting Yak Master
183 Posts |
Posted - 2004-08-27 : 16:39:15
|
| Perfect!!as usual!thanks again for all your help!!take caretony |
 |
|
|
|
|
|