Immediate php group by help. Someone please

Discussion in 'PHP' started by tom007, Jan 19, 2007.

  1. #1
    Hi,

    I am using this query to find group links and grouping number of votes on them and then sorting it

    If i don't put order by, everything is fine....but as soon as i put order by the query becomes slow and my page cannot open


    select sum(votes) as votes,url from sortingdisplay where mydate>=DATE_ADD(CURRENT_DATE,INTERVAL -7 DAY) and mydate<=CURRENT_DATE Group by url ORDER BY votes


    Is there any alternative to sort rather than order by...because order by is causing all this problem
     
    tom007, Jan 19, 2007 IP
  2. vvoole

    vvoole Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    1) You can try to use query without 'order by' and sort array with php function sort()

    2) Is this part of query obligatory?
     'mydate<=CURRENT_DATE' 
    Code (markup):
    I mean that as I see you try to get link of last 7 days. But query is doing in 'now' in any case =) I think this condition is out of place.

    3) Try to remake your one query in two different and simple.
     
    vvoole, Jan 19, 2007 IP
  3. tom007

    tom007 Active Member

    Messages:
    362
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Hi,

    PHP sort function makes it really slow and if i remove mydate <=current date, it doesn't help

    But if i remove Order by then the query works in .0005 secs which is great

    So i need a solution for order by
     
    tom007, Jan 19, 2007 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    There isn't really a 'solution' for it as such, though it might pay to add an index on the votes column... that might speed things up a bit.
     
    TwistMyArm, Jan 19, 2007 IP