Re: complicated query (newbie..)

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: complicated query (newbie..)
Date: 2009-04-09 15:44:34
Message-ID: 20090409154433.GQ12225@frubble.xen.chris-lamb.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Apr 09, 2009 at 04:47:32PM +0200, Marcin Krol wrote:
> I've got 3 tables: hosts (with host.id column) and reservation (with
> reservation.id column) in many-to-many relation, and reservation_hosts
> which is an association table (with reservation_id and host_id columns).
>
> So I've got this query which selects hosts and reservations under
> certain conditions:

If you could describe what you want in words it would help more. I
think you want something like "I was a list of all hosts and their first
reservation that doesn't cover some specific date".

If that's correct; you've got a couple of choices, either turn the inner
join into an outer join and move it up to join onto the hosts, or get
rid of it completely and use the DISTINCT ON clause.

--
Sam http://samason.me.uk/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marcin Krol 2009-04-09 16:08:04 Re: complicated query (newbie..)
Previous Message Marcin Krol 2009-04-09 15:40:22 Re: complicated query (newbie..)