From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
---|---|
To: | operationsengineer1(at)yahoo(dot)com |
Cc: | "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: SQL Question - Almost, Not Quite... |
Date: | 2006-05-25 21:17:54 |
Message-ID: | 20060525211754.GA31955@wolff.to |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On Thu, May 25, 2006 at 13:56:09 -0700,
operationsengineer1(at)yahoo(dot)com wrote:
>
> Row / inspect_result / inspect_id
> 1 / t / 107
> 2 / t / 106
> 3 / f / 100
> 4 / t / 100
>
> i can't figure out how to group by
> t_inspect.inspect_id and limit the query to one result
> per inspect_id.
>
> iow, i want to see...
>
> Row / inspect_result / inspect_id
> 1 / t / 107
> 2 / t / 106
> 3 / f / 100
>
> when i apply a limit 1, it returns a single result,
> not a single result per inspect_id. i tried (), but
> to no avail.
OK, I thought you were only querying one id at a time and the issue was
getting back an f avleu when there was a mixture of f and t values.
To get one value per inspect_id you can use the Postgres extension DISTINCT ON
to return one record per inspect_id. If you also ORDER BY inspect_id,
inspect_result then you should get a row with an f for inspect result if there
is one. Or if you only care about inspect_id's where there is at least one
row with an f, then you can add NOT inspect_id to the WHERE conditions.
From | Date | Subject | |
---|---|---|---|
Next Message | operationsengineer1 | 2006-05-25 21:30:05 | Re: SQL Question - Almost, Not Quite... |
Previous Message | operationsengineer1 | 2006-05-25 20:56:09 | Re: SQL Question - Almost, Not Quite... |