Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

MySQL syntax error

  • 06-03-2006 7: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,521 ✭✭✭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


  • Registered Users, Registered Users 2 Posts: 7,521 ✭✭✭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


Advertisement