Trouble creating MySQL query in Symfony containing JOIN and RAND()

前端 未结 2 643
挽巷
挽巷 2021-01-17 05:03

How do I do this:

SELECT t.id 
FROM table t 
JOIN (SELECT(FLOOR(max(id) * rand())) AS maxid FROM table) 
AS tt 
ON t.id >= tt.maxid 
LIMIT 1
2条回答
  •  余生分开走
    2021-01-17 05:28

    $connection = Doctrine_Manager::getConnection()->getDbh(); 
    

    won't work... Try this:

    $connection = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
    

    Then:

    $stmt = $connection->query('SELECT * FROM some_table');
    $stmt->execute();
    $result = $stmt->fetchAll();
    

提交回复
热议问题