On Thu, 4 Feb 2016 20:40:56 +0000
Simon Slavin <slavins at bigfraud.org> wrote:

> 
> On 4 Feb 2016, at 7:16pm, Luuk <luuk34 at gmail.com> wrote:
> 
> > Will this simple solution be too slow?:
> > 
> > SELECT id, room, date, time
> > FROM rooms
> > LEFT JOIN bookngs ON rooms.id=bookings.room
> > GROUP BY rooms.id, bookings.date
> > HAVING bookings.date=MAX(bookings.date) OR bookings.date IS NULL
> 
> That's the solution (a phrasing of it) that I thought of.  However, in my 
> head it's inefficient because of the test for MAX.  I was hoping for 
> something that looked better.  But it is plenty fast enough for my purposes 
> so any objection is purely for elegance and not for logic.
> 
> Thanks to you, John McKown and Dr Hipp.  I'll have a field day testing these 
> out tomorrow.
> 
> Simon.

So what about a trigger storing the last booking date/time in a dedicated table?

-- 
Yannick Duch?ne

Reply via email to