Possible Duplicate:
Trouble creating MySQL query in Symfony containing JOIN and RAND()
SELECT s.content
FROM table SdumpPost s
JOIN (SELECT(FLOOR(max(id) * rand())) AS maxid FROM table)
AS ss
ON s.id >= ss.maxid
LIMIT 1
entered as:
$connection = Doctrine_Manager:开发者_运维百科:connection();
$query = 'SELECT p.content FROM table Post p JOIN (SELECT(FLOOR(max(id) * rand())) AS maxid FROM table) AS pp ON p.id >= pp.maxid LIMIT 1';
$statement = $connection->execute($query);
//retrieve random post
$result = $statement->fetch(PDO::FETCH_OBJ);
It's not working. Any ideas?
$connection = Doctrine_Manager::getConnection()->getDbh();
$result = $connection->query('SELECT ...');
精彩评论