View Single Post

   
  #4 (permalink)  
Old 02-28-2008, 08:55 AM
Bill Karwin
 
Posts: n/a
Default Re: Grouping and ordering

miken32 wrote:
>> SELECT start,channel FROM programs WHERE name = '24' AND episode = 's04ep02'
>> ORDER BY start ASC LIMIT 0,1;
>>

> There are, using this example, many episodes of 24 on during the
> reporting period, so I only want to search on the name, and show the
> earliest instance of each episode.


SELECT p.*
FROM programs p LEFT JOIN programs p2
ON p.name = p2.name AND p.episode = p2.episode AND p.start > p2.start
WHERE p2.start IS NULL;

In other words, show programs for which there is no other showing of the
same episode with an earlier start time.

Regards,
Bill K.
Reply With Quote