Re: [GENERAL] retrieving primary key for row with MIN function

2009-05-01 Thread Erick Papadakis
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

Re: [GENERAL] retrieving primary key for row with MIN function

2009-04-30 Thread Richard Broersma
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.

Re: [GENERAL] retrieving primary key for row with MIN function

2009-04-30 Thread Scott Marlowe
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

[GENERAL] retrieving primary key for row with MIN function

2009-04-30 Thread Marcin Krol
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