Reputation: 69
I got the following query but it is not working. Any help appreciated.
mysql_query("SELECT * FROM
(SELECT * FROM Names WHERE suffix='1' AND word!='$main_suffix' ORDER BY votes DESC LIMIT 15)
ORDER BY Rand() LIMIT 3");
Upvotes: 0
Views: 24
Reputation: 133360
You must add the alias eg:as t at the end of subselect
mysql_query("SELECT * FROM
(SELECT *
FROM Names
WHERE suffix='1'
AND word!='$main_suffix'
ORDER BY votes DESC LIMIT 15) as t
ORDER BY Rand() LIMIT 3");
Upvotes: 0
Reputation: 33511
All subselects need an alias:
mysql_query("SELECT * FROM (
SELECT * FROM Names
WHERE suffix='1' AND word!='$main_suffix'
ORDER BY votes DESC LIMIT 15)
) YourAliasName
ORDER BY Rand() LIMIT 3");
Also, don't use mysql_query
, but use MySQLi or PDO instead.
Upvotes: 1