sql - MySQL select lowest timedate for each id -


i have table :

create table if not exists `event_showtime` (   `id_show` int(11) not null auto_increment,   `id_event` int(11) not null,   `latitude` double not null,   `longitude` double not null,   `event_date_time` datetime not null,   primary key (`id_show`),   key `id_event` (`id_event`) ) 

values this, example :

insert `event_showtime` (`id_show`, `id_event`, `latitude`, `longitude`, `event_date_time`) values (1, 1, 49.2016762922894, 18.7615620750428, '2014-03-31 16:13:17'), (2, 1, 49.2016762922894, 18.7615620750428, '2014-04-01 20:00:00'), (3, 2, 49.2113914818564, 18.7520992416382, '2014-03-31 15:00:00'), (4, 2, 49.0545135142313, 20.2952223676682, '2014-04-16 11:00:00'), (5, 2, 49.2113914818564, 18.7520992416382, '2014-04-23 11:00:00'), (6, 2, 49.0545135142313, 20.2952223676682, '2014-04-30 11:00:00'), (7, 2, 49.2016762922894, 18.7615620750428, '2014-04-29 12:00:00'), (8, 1, 49.2016762922894, 18.7615620750428, '2014-04-24 12:00:00'); 

i select result in such way :

for each id_event want select nearest date, > now() result should :

`id_event` `event_date_time`  1 , '2014-04-24 12:00:00'  2 , '2014-04-16 11:00:00' 

how achive ? :)

select id_event, min(event_date_time) lowest_date event_showtime event_date_time > now() group id_event 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -