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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.