Reputation: 189
could someone tell me whats wrong on this mysql query?
$p = mysql_query("SELECT name,subname FROM brands GROUP BY name WHERE
having count(*) > 10 ORDER BY RAND() LIMIT 1")or die(mysql_error());
it says:
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 'WHERE having count(*) > 10 ORDER BY RAND() LIMIT 1' at line 1
Upvotes: 1
Views: 65
Reputation: 74217
HAVING
does not use a WHERE
clause, remove it.
$p = mysql_query("SELECT name,subname FROM brands GROUP BY name
having count(*) > 10 ORDER BY RAND() LIMIT 1")or die(mysql_error());
Consult:
You should consider switching to PDO with prepared statements or mysqli_*
with prepared statements, as the mysql_*
functions are deprecated.
Upvotes: 2
Reputation: 10385
Remove the WHERE
clause, you already have a HAVING
clause.
So, your statement must be :
$p = mysql_query("SELECT name,subname FROM brands GROUP BY name HAVING count(*) > 10 ORDER BY RAND() LIMIT 1")or die(mysql_error());
Upvotes: 1