From: | "Aaron Bono" <postgresql(at)aranya(dot)com> |
---|---|
To: | "Richard Broersma Jr" <rabroersma(at)yahoo(dot)com> |
Cc: | "Phillip Smith" <phillips(at)weatherbeeta(dot)com(dot)au>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: SELECT Aggregate |
Date: | 2006-06-29 15:25:05 |
Message-ID: | bf05e51c0606290825s218dac29veda8a8ec03ff1360@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
I am not familiar enough with how postgres optimizes the queries but won't
this end up with
total number of queries run on DB = 1 query + 1 query/row in first query
What would be more efficient on a large database - a query like Richard
submitted (subquery in the select) or one like I submitted (join the two
tables and then do a group by)? My guess is it depends on the % of records
returned out of the sales_orders table, the smaller the % the better
Richard's query would perform, the higher the % the better the join would
run.
The database I am working with aren't big enough yet to warrant spending a
lot of time researching this but if someone with more experience knows what
is best I would love to hear about it.
Thanks,
Aaron Bono
On 6/29/06, Richard Broersma Jr <rabroersma(at)yahoo(dot)com> wrote:
>
> > SELECT trans_no,
> > customer,
> > date_placed,
> > date_complete,
> > date_printed,
> > ord_type,
> > ord_status,
> select (
> SUM(sell_price)
> from soh_product
> where sales_orders.trans_no = soh_product.soh_num
> ) as transact_sum,
> > customer_reference,
> > salesman,
> > parent_order,
> > child_order,
> > order_number
> > FROM sales_orders
> > WHERE (trans_no Like '8%' AND order_number Like '8%')
> > OR (trans_no Like '9%' AND order_number Like '8%')
> > OR (trans_no Like '8%' AND order_number Like '9%')
> > OR (trans_no Like '9%' AND order_number Like '9%')
> > AND (warehouse='M')
> > AND (date_placed > (current_date + ('12 months ago'::interval)))
> > ORDER BY trans_no DESC
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Aaron Bono | 2006-06-29 15:30:39 | Re: can any one solve this problem |
Previous Message | Markus Schaber | 2006-06-29 13:50:21 | Re: Data Entry and Query forms |