Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query most recent row for each IP? 1

Status
Not open for further replies.

Yrrk

IS-IT--Management
Aug 22, 2004
180
US
Anyone know off the top of their head how i'd run a query to get the most recent entries (datetime) for any given IP?

Code:
mysql> describe Stats;
+------------+--------------+------+-----+---------------------+-------+
| Field      | Type         | Null | Key | Default             | Extra |
+------------+--------------+------+-----+---------------------+-------+
| DateTime   | datetime     |      |     | 0000-00-00 00:00:00 |       |
| Used       | varchar(11)  |      |     | 0                   |       |
| Avail      | varchar(11)  |      |     | 0                   |       |
| MPS        | float(5,2)   |      |     | 0.00                |       |
| Sending    | char(1)      |      |     |                     |       |
| Receiving  | char(1)      |      |     |                     |       |
| NumSMAP    | mediumint(9) |      |     | 0                   |       |
| NumSenders | mediumint(9) |      |     | 0                   |       |
| IP         | varchar(15)  |      |     |                     |       |
| AvgSize    | float(9,0)   |      |     | 0                   |       |
| Perc       | mediumint(9) |      |     | 0                   |       |
+------------+--------------+------+-----+---------------------+-------+
 
How about:
[tt]
SELECT ip,MAX(`datetime`)
FROM stats
GROUP BY ip
[/tt]
 
Sorry, it's "most recent entries for any given ip". In that case:
[tt]
SELECT *
FROM stats
WHERE ip='1.2.3.4'
ORDER BY `datetime` DESC
LIMIT 10
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top