944,106 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 1310
  • MySQL RSS
Dec 2nd, 2007
0

Same query, one difference

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
natashenka_66 is offline Offline
2 posts
since Dec 2007
Dec 3rd, 2007
0

Re: Same query, one difference

Since you want to run exactly the same query and check only for one condition, you can do it this way.

php Syntax (Toggle Plain Text)
  1. $query="select * from huge_table where conditions joins etc";
  2. $result=mysql_query($query);
  3. $price_p=array();
  4. $price_s=array();
  5. while($row=mysql_fetch_array($result,MYSQL_ASSOC)){
  6. if($row['price']=="P"){
  7. array_push($price_p,$row['price']);
  8. }
  9. if($row['price']=="S"){
  10. array_push($price_s,$row['price']);
  11. }
  12. }

So, by the end of the execution of this query, you will have 2 arrays, 1 with price=p values and the other with price=s values.

Cheers,
Naveen.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Dec 3rd, 2007
0

Re: Same query, one difference

Thank you for your reply, but i wasn't clear.
Roughly my code:
MySQL Syntax (Toggle Plain Text)
  1. SELECT * FROM sales_item d
  2.  
  3.  
  4.  
  5. JOIN (SELECT STR_TO_DATE('2007-09-30', '%Y-%m-%d') st_date) v
  6.  
  7.  
  8.  
  9. JOIN item_store f on f.item_no=d.item_no AND f.store_id = d.store_id
  10.  
  11.  
  12.  
  13. JOIN item_sellprice_store a on f.item_no=a.item_no AND f.store_id = a.store_id
  14.  
  15.  
  16.  
  17. JOIN item b on f.item_no=b.item_no
  18.  
  19.  
  20.  
  21. JOIN item_supplier c on b.item_no=c.item_no AND b.supplier_no=c.supplier_no
  22.  
  23.  
  24.  
  25. JOIN item_sellprice_storegroup g on a.batch_id=g.batch_id
  26.  
  27.  
  28.  
  29.  
  30.  
  31. JOIN store k on f.store_id =k.store_id
  32.  
  33.  
  34.  
  35. WHERE d.store_id = '011'
  36.  
  37.  
  38.  
  39. AND (f.item_status ='A' OR f.item_status ='O')
  40.  
  41.  
  42.  
  43. AND a.price_type='P'
  44.  
  45.  
  46.  
  47. AND a.effective_start_date < v.st_date < a.effective_end_date
  48.  
  49.  
  50.  
  51. AND d.sale_date = v.st_date
  52.  
  53.  
  54.  
  55. ORDER BY d.category_code, a.sell_gst, a.item_no ;

And the second one is exactly the same apart from highlighted line (it▓s a.price_type='S')

I need a query, not a script.
Thank you so much.
Last edited by natashenka_66; Dec 3rd, 2007 at 5:46 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
natashenka_66 is offline Offline
2 posts
since Dec 2007
Dec 4th, 2007
0

Re: Same query, one difference

Umm.. I didnt get you. Do you type this query in phpmyadmin/mysql prompt directly without using a php interface ? How do you generate a BIRT report ?What I said was, remove the condition and a.price_type='P' . Then compare the result with the price_type.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Problem on IF STATEMENT on TRIGGER with MySql
Next Thread in MySQL Forum Timeline: New to databases





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC