SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 4th, 2004, 02:58 PM
lklektau lklektau is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 lklektau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy need help with complicated select distinct query

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.

Reply With Quote
  #2  
Old June 4th, 2004, 05:13 PM
lklektau lklektau is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 lklektau User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #3  
Old June 4th, 2004, 05:15 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
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-

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > need help with complicated select distinct query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT