User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,760 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 866 | Replies: 3
Reply
Join Date: Dec 2007
Posts: 2
Reputation: natashenka_66 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
natashenka_66 natashenka_66 is offline Offline
Newbie Poster

Same query, one difference

  #1  
Dec 2nd, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Same query, one difference

  #2  
Dec 3rd, 2007
Since you want to run exactly the same query and check only for one condition, you can do it this way.

  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.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Dec 2007
Posts: 2
Reputation: natashenka_66 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
natashenka_66 natashenka_66 is offline Offline
Newbie Poster

Re: Same query, one difference

  #3  
Dec 3rd, 2007
Thank you for your reply, but i wasn't clear.
Roughly my code:
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 ;

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.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Same query, one difference

  #4  
Dec 4th, 2007
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.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 9:26 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC