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

前端 未结 2 640
挽巷
挽巷 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();
    
    0 讨论(0)
  • 2021-01-17 05:30
    $connection = Doctrine_Manager::getConnection()->getDbh(); 
    $result = $connection->query('SELECT ...'); 
    
    0 讨论(0)
提交回复
热议问题