SQL not working?

Discussion in 'MySQL' started by almondj, Dec 19, 2009.

  1. #1
    What's wrong with this bit of code?

    $results = mysql_query("SELECT email, SUM(confirm) AS total FROM survey WHERE prize = 'bf3' GROUP BY ip ORDER BY total DESC");

    I'm trying to rank people for a prize where the prize is "bf3" and sum the "confirm" column (where the actual sum comes from). Can't figure out what's wrong.
     
    almondj, Dec 19, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    is it giving some error? or query is working fine but not giving desired output?
    it would be great if you can share sample data and table structure.
     
    mastermunj, Dec 20, 2009 IP
  3. solarpanelsdirect

    solarpanelsdirect Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    your query is correct, what is the error you are getting? This is indeed a little vague.
     
    solarpanelsdirect, Dec 20, 2009 IP
  4. rayqsl

    rayqsl Active Member

    Messages:
    91
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    53
    #4
    What error are you getting?

    I notice that you're selecting email but grouping by ip. This is not OK in standard SQL - you can only select columns that you are grouping by or aggregates (such as count(*)).

    We need to know what the error is.
     
    rayqsl, Dec 21, 2009 IP
  5. almondj

    almondj Peon

    Messages:
    768
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #5
    It didn't throw any errors for some reason. I then changed the prize to 'game' instead of 'bf3' and it worked, literally, nothing else changed except the prize. I've run into this before with more common words though, not this, for example: "order."
     
    almondj, Dec 21, 2009 IP