1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

#2014 - Commands out of sync; you can't run this command now

Discussion in 'General PHP and MySQL Discussions' started by Jaxel, Jul 24, 2015.

  1. Jaxel

    Jaxel Well-Known Member

    I am trying to run some MySQL code...
    Code:
    SELECT *,
        event_players - event_claimed AS event_unclaimed
    FROM EWRtorneo_events
    WHERE event_state = 'visible' AND league_id = 1
        ORDER BY event_date DESC, event_name DESC
    Now this error ONLY shows up when the search results contains a row where the column for event_players is equal to 0. What does this error mean?

    If I remove either:
    • event_players - event_claimed AS event_unclaimed
    • ORDER BY event_date DESC, event_name DESC
    Then the code starts working. However, both those lines are essential for my function.
     
  2. Jaxel

    Jaxel Well-Known Member

    I figured it out... if either of the variables in the subtraction statement in MySQL is an unsigned integer, then the result must always be an unsigned integer as well. If there is ever an instance where the result could be negative, the command will fail.

    I solved this by casting the variables as signed:
    Code:
    SELECT *,
        CAST(event_players AS SIGNED) - CAST(event_claimed AS SIGNED) AS event_unclaimed
    FROM EWRtorneo_events
    WHERE event_state = 'visible' AND league_id = 1
        ORDER BY event_date DESC, event_name DESC
     

Share This Page