I don't know much about SQL but your syntax looks wrong.
*query_sql "your MySQL query", <array variable> {,<array variable>, ...};
*query_logsql "your MySQL query", <array variable> {,<array variable>, ...};
Puts up to 128 rows of values into the arrays and returns the number of rows.
Example:
set @nb, query_sql("select name,fame from `char` ORDER BY fame DESC LIMIT 5", @name$, @fame);
mes "Hall Of Fame: TOP5";
mes "1."+@name$[0]+"("+@fame[0]+")"; // Will return a person with the biggest fame value.
mes "2."+@name$[1]+"("+@fame[1]+")";
mes "3."+@name$[2]+"("+@fame[2]+")";
mes "4."+@name$[3]+"("+@fame[3]+")";
mes "5."+@name$[4]+"("+@fame[4]+")";
Note: In the TXT version it doesn't fill the array and always return -1.
Note: Use $ as suffix in the array to receive all data as text.
Note: The difference between query_sql and query_logsql is that the latter
uses the sql connection to the log database, and should be used when you want
to query the server log tables.
https://rathena.svn.sourceforge.net/svnroot/rathena/trunk/doc/script_commands.txt