brianlange Posted February 23, 2012 Share Posted February 23, 2012 My Oracle table columns are: message_id, status, start_time There is no primary key. There are multiple rows for each message_id. I would like to be able to select records where the record that has the mininum start_time value for records grouped by message_id has a status value of 'PC' Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/257659-group-by-with-where-clause/ Share on other sites More sharing options...
Zane Posted February 23, 2012 Share Posted February 23, 2012 you mean like SELECT status, start_time, message_id FROM yourTable ORDER BY start_time DESC GROUP BY status Quote Link to comment https://forums.phpfreaks.com/topic/257659-group-by-with-where-clause/#findComment-1320585 Share on other sites More sharing options...
brianlange Posted February 24, 2012 Author Share Posted February 24, 2012 I don't think that is going to work. I only want the records where the min(start_time) for records grouped by message_id has a status value of 'PC' I was able to get a result with the following. Is there a better way to do this? select message_id from table where start_time in (select min(start_time) from table group by message_id) and status = 'PC' Quote Link to comment https://forums.phpfreaks.com/topic/257659-group-by-with-where-clause/#findComment-1320637 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.