Link Posted September 8, 2008 Share Posted September 8, 2008 Hello. I need help with a query. I have two tables 'events', and 'event_details'. 'events' holds the general information for an event, and 'event_details' can have multiple entries for each event listed in 'events'. The 'event_details' has a column `datetime` that has the start date and time (in time() format) for that part of the event. I want to get the events from the 'events' table in descending order by the `datetime` that occurs first. This is confusing to explain, but I have included the structures below in hopes that it helps. Thanks in advance! -- -- Table structure for table `events` -- CREATE TABLE IF NOT EXISTS `events` ( `id` int(11) unsigned NOT NULL auto_increment, `name` varchar(100) NOT NULL, `description` text NOT NULL, `for_everyone` tinyint(1) NOT NULL default '0', `for` text NOT NULL, `for_other` text NOT NULL, `rsvp_required` tinyint(1) NOT NULL, `announce` tinyint(1) NOT NULL, `announce_text` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -------------------------------------------------------- -- -- Table structure for table `event_details` -- CREATE TABLE IF NOT EXISTS `event_details` ( `id` int(11) unsigned NOT NULL auto_increment, `event_id` int(11) unsigned NOT NULL default '0', `datetime` int(11) unsigned NOT NULL default '0', `datetime_end` int(11) unsigned NOT NULL default '0', `capacity` int(3) NOT NULL, `location` varchar(100) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; Quote Link to comment https://forums.phpfreaks.com/topic/123343-query-help/ Share on other sites More sharing options...
Ken2k7 Posted September 9, 2008 Share Posted September 9, 2008 What datetime? ??? Quote Link to comment https://forums.phpfreaks.com/topic/123343-query-help/#findComment-637100 Share on other sites More sharing options...
DarkWater Posted September 9, 2008 Share Posted September 9, 2008 What datetime? ??? Indeed. Quote Link to comment https://forums.phpfreaks.com/topic/123343-query-help/#findComment-637111 Share on other sites More sharing options...
Link Posted September 9, 2008 Author Share Posted September 9, 2008 In the 'event_details' table, there is a column named `datetime`. Quote Link to comment https://forums.phpfreaks.com/topic/123343-query-help/#findComment-637222 Share on other sites More sharing options...
fenway Posted September 10, 2008 Share Posted September 10, 2008 I want to get the events from the 'events' table in descending order by the `datetime` that occurs first. This is confusing to explain, but I have included the structures below in hopes that it helps. Easiest way to the use max(datetime) on the details table with a group by eventID, and then join in this derived table back to the main events table for event-based fields. Quote Link to comment https://forums.phpfreaks.com/topic/123343-query-help/#findComment-638344 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.