Doctrine
Doctrineは、Doctrine_QueryではFrom句にサブクエリを指定できないんだね。
少なくとも、ローカルの1.2.4のバージョンではエラーになる。
とりあえず、Doctrine_RawSqlを使って書いてみる。
$q = new Doctrine_RawSql();
$q->addComponent('s', 'Sample')
- >select('{s.id}, {s.name}, {s.login_at}')
- >from('(SELECT * FROM Sample s ORDER BY s.login_at desc limit 100) s')
- >orderBy('rand()')
- >limit(10);
$q->execute(array(), Doctrine::HYDRATE_ARRAY);
でも一応、FROMでも指定できると書かれているけどね。
サンプルはSELECTとWHEREしかないけど。
http://www.doctrine-project.org/documentation/manual/1_1/en/dql-doctrine-query-language%3Asubqueries
実際のところどうなんでしょうか。