Skip site navigation (1) Skip section navigation (2)

Re: SQL Question - S/B Good...

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 - S/B Good...
Date: 2006-05-26 05:02:58
Message-ID: 20060526050258.GA7359@wolff.to (view raw or flat)
Thread:
Lists: pgsql-novice
On Thu, May 25, 2006 at 14:56:51 -0700,
  operationsengineer1(at)yahoo(dot)com wrote:
> 
> Bruno,
> 
> This looks like it does what i want...
> 
> SELECT DISTINCT ON (t_inspect_result.inspect_id)
> t_inspect_result.inspect_id,
> t_inspect_result.inspect_result,
> t_inspect_result.inspect_timestamp
> FROM t_inspect_result, t_inspect, t_inspect_area,
>      t_serial_number,
> t_link_contract_number_job_number, t_job_number,
> t_product
> WHERE  t_inspect.inspect_area_id =
>        t_inspect_area.inspect_area_id
> AND t_inspect.serial_number_id =
>     t_serial_number.serial_number_id
> AND t_serial_number.link_contract_number_job_number_id
> =
>    
> t_link_contract_number_job_number.link_contract_number_job_number_id
> AND t_link_contract_number_job_number.job_number_id =
>     t_job_number.job_number_id
> AND t_product.product_id =
>     t_job_number.product_id
> AND t_inspect.inspect_id =
>     t_inspect_result.inspect_id
> AND t_inspect.serial_number_id = '184'
> ORDER BY t_inspect_result.inspect_id DESC,
>          t_inspect_result.inspect_timestamp DESC
> -- inspect_id desc impacts end result.  time desc
> -- impacts the groups prior to being distinctly listed
> 
> as you can see in the note, the timestamp DESC works
> within the groups, not on the single group value
> ultimately returned (as it should).  how can i get it
> to work on returned groups, too?  i work around it by
> putting inspect_id in desc order (they typically occur
> one after another), but that may not always work.

It would be nice to see some sample data, output and explains.

In response to

pgsql-novice by date

Next:From: Shreehari SDate: 2006-05-26 11:47:05
Subject: Urgent Help
Previous:From: Michael FuhrDate: 2006-05-25 22:42:15
Subject: Re: exception handling in plpgsql

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group