MYSQL query

Kiran Annaiah <[email protected]> Fri, 28 Dec 2007 10:47:48 -0600
Newsgroups gmane.comp.db.mysql.perl
Message-ID <[email protected]>
Hi I am tryin out a query to get the newest entry of a particular value.

Query1

select distinct pat_id, max(visit_time) from cag_pp2test.visit where visit_id in (
select visit_id from cag_pp2test.diagnosis where diag_icd9 like "555%" or diag_icd9 like "556%")
group by visit_time;

and the result was..

pat_id              visit_time  
593810537    00:15:00
8174391599    00:26:00
1599174133    00:27:00
9439759022    00:29:00
7065947263    00:32:00
5850634830    00:36:00


Crosscheck query
Query 2

select distinct pat_id, max(visit_time) from cag_pp2test.visit where pat_id = '593810537'
group by visit_time;

and result was

pat_id           visit_time
593810537    00:15:00 (first result row)
593810537    03:33:00
593810537    07:49:00
593810537    08:01:00
593810537    08:31:00
...
...
...
593810537    21:03:00
593810537    21:08:00
593810537    21:10:00 (last result row)


and i feel it is just returning the first value from visit_time column. How does it sort the max time values?
Was a little confused, was wondering if my query was pulling the time out correctly.

Any suggestions would be of great help

thank you
Kiran



_________________________________________________________________
i’m is proud to present Cause Effect, a series about real people making a difference.
http://im.live.com/Messenger/IM/MTV/?source=text_Cause_Effect