可能重复:
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
输入:
$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);
它不起作用。有什么想法吗?
答案 0 :(得分:0)
$connection = Doctrine_Manager::getConnection()->getDbh();
$result = $connection->query('SELECT ...');