View Full Version : Simplying a few MySQL Queries - Help Needed
CommuneZoom
26 Oct 2005, 04:33
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.
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Is there an alternative, of will I be stuck making 4 seperate calls?
Danny.VBT
26 Oct 2005, 04:48
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!
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
CommuneZoom
26 Oct 2005, 05:09
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!
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
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).
Danny.VBT
26 Oct 2005, 05:12
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...
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
I think the logic may be backwards in that, totalactive should be when ispending = 0.
Try ;
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Marco van Herwaarden
26 Oct 2005, 13:43
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
finished.
Danny.VBT
26 Oct 2005, 17:53
Can you explain this bit?
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
I've never seen this before...
Marco van Herwaarden
26 Oct 2005, 18:43
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.
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
finished.
Interesting question, is it quicker to use a more complicated SQL query, or a simpler query and a bit of PHP.
Marco van Herwaarden
26 Oct 2005, 21:48
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.
Danny.VBT
26 Oct 2005, 22:14
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 :)
can IF be used within the parameters of where?
Marco van Herwaarden
27 Oct 2005, 05:14
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/en/control-flow-functions.html
Danny.VBT
27 Oct 2005, 06:03
/me clicks link
There's so much stuff I haven't even learned yet, Ah! Thanks again Marco. :)
i was asking because of this:
http://www.vbulletin.org/forum/showthread.php?t=94088
vBulletin® v3.6.12, Copyright ©2000-2013, Jelsoft Enterprises Ltd.