Could you end the query with a "LIMIT 1"?
SELECT h.id AS host_id, MIN(r.start_date) AS reservation_start_date, r.id AS
reservation_id
FROM hosts h
LEFT OUTER JOIN reservation_hosts rh ON rh.host_id = h.id
LEFT OUTER JOIN reservation r ON r.id = rh.reservation_id AND
(r.start_date, r.end_date) OVE
On Wed, Apr 29, 2009 at 5:30 AM, Marcin Krol wrote:
> I need to retrieve PK (r.id in the query) for row with MIN(r.start_date),
> but with a twist: I need to select only one record, the one with minimum
> date.
If you mean on row period then just add a limit 1 to the end of your
existing query.
On Wed, Apr 29, 2009 at 6:30 AM, Marcin Krol wrote:
> Hello everyone,
>
> I need to retrieve PK (r.id in the query) for row with MIN(r.start_date),
> but with a twist: I need to select only one record, the one with minimum
> date.
>
> Doing it like this does not solve the problem:
>
> SELECT h.id
Hello everyone,
I need to retrieve PK (r.id in the query) for row with
MIN(r.start_date), but with a twist: I need to select only one record,
the one with minimum date.
Doing it like this does not solve the problem:
SELECT h.id AS host_id, MIN(r.start_date) AS reservation_start_date,
r.id A