Click to See Complete Forum and Search --> : Two same queries with one different "where"


natashenka_66
12-02-2007, 06:41 PM
Hello!
I have a query with multiple table joints and where clauses. Tables are huge and query runs for a very long time. I need to run another query, which is exactly the same apart for one Where clause (first time price = "P", second time price = "S"). I use this for BIRT report, which means I need to have a result of there two queries at the same time. I can run them at the same time, but because they are both huge it takes a Long time. I wonder if I can make only one query, will it be faster? And if it will- what’s the best way to make it?
Thank you for your help!
Please let me know if it is not clear.

chazzy
12-02-2007, 07:58 PM
what if you use a view to speed up performance?

natashenka_66
12-02-2007, 08:05 PM
I can, but i can't see how can i join two same SQL with only one different Where? Can you please just roughly show it to me?? Thank you

natashenka_66
12-02-2007, 08:27 PM
this is roughly the SQL:
Select * FROM sales_item d

join (select str_to_date('2007-09-30', '%Y-%m-%d') st_date) v

join item_store f on f.item_no=d.item_no and f.store_id = d.store_id

join item_sellprice_store a on f.item_no=a.item_no and f.store_id = a.store_id

join item b on f.item_no=b.item_no

join item_supplier c on b.item_no=c.item_no and b.supplier_no=c.supplier_no

join item_sellprice_storegroup g on a.batch_id=g.batch_id


join store k on f.store_id =k.store_id

where d.store_id = '011'

and (f.item_status ='A' or f.item_status ='O')

and a.price_type='P'

and a.effective_start_date < v.st_date < a.effective_end_date

and d.sale_date = v.st_date

order by d.category_code, a.sell_gst, a.item_no ;

Only a.price_type='P' line is different.

Thank you!!