Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

MySQL syntax error

  • 06-03-2006 08:18PM
    #1
    Registered Users, Registered Users 2 Posts: 673 ✭✭✭


    Hey,

    I am using the following php code to select the max value from a mysql table. I have used this exact code before for a similar purpose on a different site.
    $query = "SELECT percentage, your_answer
    		FROM g1_w1_q1_percentage_frequency
    		WHERE percentage = (SELECT MAX(percentage) FROM g1_w1_q1_percentage_frequency)
    		";
    		$results = mysql_query($query)
    			or die(mysql_error());
    
    		while ($rows = mysql_fetch_array($results)) {
    		extract ($rows);
    		}
    

    When i try and view the results in my browser i get the following mysql error:
    You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT MAX(percentage) FROM `g1_w1_q1_percentage_frequency` )'
    

    This makes no sense to me because this exact code is working for me on the other site.

    The only thing i could think of that might be causing the problem is that the other site is working off a different version on mysql (but i dont think it is) so i did a direct query in mysql. When i do a direct query it works fine:
    SELECT MAX(percentage) FROM `g1_w1_q1_percentage_frequency`
    

    Anyone know why this might be happening?

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 4,003 ✭✭✭rsynnott


    Don't think MySQL supports nested queries. You COULD do something along the lines of SELECT a, b, FROM table ORDER BY a DESC LIMIT 0,1
    but I suspect there should be a better way.


  • Registered Users, Registered Users 2 Posts: 7,830 ✭✭✭jmcc


    Hey,

    I am using the following php code to select the max value from a mysql table. I have used this exact code before for a similar purpose on a different site.
    What version of MySQL are you having problems with?

    Regards...jmcc

    Regards…jmcc



  • Registered Users, Registered Users 2 Posts: 7,830 ✭✭✭jmcc


    rsynnott wrote:
    Don't think MySQL supports nested queries.
    Some versions 4.1.nn+, I think,do. However if I rem correctly, 4.0.nn and before do not.

    Regards...jmcc

    Regards…jmcc



Advertisement