Jump to content

Query Help


Link

Recommended Posts

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 ;

Link to comment
https://forums.phpfreaks.com/topic/123343-query-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/123343-query-help/#findComment-638344
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.