|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have a table called gms_tests that keeps track of the results of tests run against servers. Columns are hostname, testname, status and time. The tests are run (about 5 against each server) every half hour, and the results are put in the table.
I need to be able to search this table and obtain the most recent result for each test. For example, I need something similar to: select distinct hostname,testname from gms_tests order by time desc but I also need to be able to see the time and status columns. I've tried something like this: select hostname,testname,status,max(time) from gms_tests group by hostname,testname but the data returned in the status column is not correct - it doesn't match the status that corresponds with the latest test time. Any ideas what might work? I'm using MySQL version 3.23.58, so I can't use subqueries. |
|
#2
|
|||
|
|||
|
re: need help with complicated select distinct query
after searching for a few more hours, I managed to find the answer myself. If anyone is interested in the solution, I found it at:
URL Look in the comments posted at the bottom of the page for a nice simple way of doing it. Note that this method though is extremely slow if you have a big table. |
|
#3
|
|||
|
|||
|
Select Top 25 gms_tests.* from gms_tests order by gms_tests.Time Desc;
The 25 is the 5 times the number of servers (I figured 5) tested. This gives you the last 25 records based on the most recent time S- |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > need help with complicated select distinct query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|