Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 26 Oct 2005, 04:33
CommuneZoom CommuneZoom is offline
 
Join Date: Sep 2005
Simplying a few MySQL Queries - Help Needed

I have the following queries that, if possible, I need to simplify. I'd like to knock this down to as few queries as possible as I will need to call additional (probably 2 other items) from the same row.

I am just looking to get the number of rows matching each set, though I'd rather knock 4 queries down to 1-2 if there is another way to do so.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Is there an alternative, of will I be stuck making 4 seperate calls?
Reply With Quote
  #2  
Old 26 Oct 2005, 04:48
Danny.VBT's Avatar
Danny.VBT Danny.VBT is offline
 
Join Date: Oct 2004
Try the below, maybe it will work. I need to start coding php more, and stop with vb.net. I'm starting to forget stuff!


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
while($coffeeMachine->supply($Danny)) { $Danny->run(); }

Twitter Blog

Last edited by Danny.VBT : 26 Oct 2005 at 04:59.
Reply With Quote
  #3  
Old 26 Oct 2005, 05:09
CommuneZoom CommuneZoom is offline
 
Join Date: Sep 2005
Originally Posted by Danny.VBT
Try the below, maybe it will work. I need to start coding php more, and stop with vb.net. I'm starting to forget stuff!


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.
Thanks for the reply, however, I need them both to be showing at the same time and not alternating.

As I need it to report the total for the entire table, the above will not work. I have 8 entries in the table and the above reports a blank for active and 1 for pending (when all 8 are pending).
Reply With Quote
  #4  
Old 26 Oct 2005, 05:12
Danny.VBT's Avatar
Danny.VBT Danny.VBT is offline
 
Join Date: Oct 2004
Originally Posted by CommuneZoom
Thanks for the reply, however, I need them both to be showing at the same time and not alternating.

As I need it to report the total for the entire table, the above will not work. I have 8 entries in the table and the above reports a blank for active and 1 for pending (when all 8 are pending).
Try it without the Count clause. So...


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
while($coffeeMachine->supply($Danny)) { $Danny->run(); }

Twitter Blog
Reply With Quote
  #5  
Old 26 Oct 2005, 07:02
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Real name: Paul Marsden
I think the logic may be backwards in that, totalactive should be when ispending = 0.

Try ;


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________


Cable Forum - DigiGuide
Please Note: I will not answer support questions via e-mail or PM - please use the relevant thread or forum.
Senior vBulletin Developer : Please do not PM me about custom work - I work for Internet brands and no longer have the time to undertake any.
Reply With Quote
  #6  
Old 26 Oct 2005, 13:43
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

finished.
__________________
Marco van Herwaarden
Ex vBulletin.org Coordinator
Reply With Quote
  #7  
Old 26 Oct 2005, 17:53
Danny.VBT's Avatar
Danny.VBT Danny.VBT is offline
 
Join Date: Oct 2004
Can you explain this bit?


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


I've never seen this before...
__________________
while($coffeeMachine->supply($Danny)) { $Danny->run(); }

Twitter Blog
Reply With Quote
  #8  
Old 26 Oct 2005, 18:43
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
if the value of ispending is '1', it will result in a value of 1, otherwise 0 (zero), if you then sum it, you will count 1 for each row that have ispending = 1.

By testing ispending = 0, you can reverse the count.
__________________
Marco van Herwaarden
Ex vBulletin.org Coordinator
Reply With Quote
  #9  
Old 26 Oct 2005, 18:50
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Real name: Paul Marsden
Originally Posted by MarcoH64
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

finished.
Interesting question, is it quicker to use a more complicated SQL query, or a simpler query and a bit of PHP.
__________________


Cable Forum - DigiGuide
Please Note: I will not answer support questions via e-mail or PM - please use the relevant thread or forum.
Senior vBulletin Developer : Please do not PM me about custom work - I work for Internet brands and no longer have the time to undertake any.
Reply With Quote
  #10  
Old 26 Oct 2005, 21:48
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
That depends totally on the query. Since this one are simple embedded functions, not used in where/order by/join conditions, i would say the query is much faster then doing it in php.
__________________
Marco van Herwaarden
Ex vBulletin.org Coordinator
Reply With Quote
  #11  
Old 26 Oct 2005, 22:14
Danny.VBT's Avatar
Danny.VBT Danny.VBT is offline
 
Join Date: Oct 2004
Originally Posted by MarcoH64
if the value of ispending is '1', it will result in a value of 1, otherwise 0 (zero), if you then sum it, you will count 1 for each row that have ispending = 1.

By testing ispending = 0, you can reverse the count.
Thanks Marco
__________________
while($coffeeMachine->supply($Danny)) { $Danny->run(); }

Twitter Blog
Reply With Quote
  #12  
Old 26 Oct 2005, 22:22
AN-net's Avatar
AN-net AN-net is offline
 
Join Date: Dec 2003
can IF be used within the parameters of where?
Reply With Quote
  #13  
Old 27 Oct 2005, 05:14
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
That wouldn't make much sense i think, the where clause is already 1 big if-statement, but i never tried.

more info: http://dev.mysql.com/doc/refman/5.0/...functions.html
__________________
Marco van Herwaarden
Ex vBulletin.org Coordinator
Reply With Quote
  #14  
Old 27 Oct 2005, 06:03
Danny.VBT's Avatar
Danny.VBT Danny.VBT is offline
 
Join Date: Oct 2004
/me clicks link

There's so much stuff I haven't even learned yet, Ah! Thanks again Marco.
__________________
while($coffeeMachine->supply($Danny)) { $Danny->run(); }

Twitter Blog
Reply With Quote
  #15  
Old 27 Oct 2005, 10:39
AN-net's Avatar
AN-net AN-net is offline
 
Join Date: Dec 2003
i was asking because of this:
http://www.vbulletin.org/forum/showthread.php?t=94088
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Jump


New To Site? Need Help?

All times are GMT. The time now is 21:05.

Layout Options | Width: Wide Color: