在纯SQL中我会这样做
select t1.id, t2.id from table1 t1 join table2 t2;
你会使用doctrine dbal querybuilder
实现同样的目标$qb = $this->_em->getConnection()->createQueryBuilder()
$qb->select('t1.id, t2.id')
->from('table1','t1')
->join('t1', 'table2', 't2') //without on clause, this doesn't work
->execute()
->fetchAll();
答案 0 :(得分:1)
试试这个
$qb->select('t1.id', 't2.id')
->from('table1','t1')
->join('t1', 'table2', 't2', true)
->execute()
->fetchAll();
答案 1 :(得分:1)
没有“ON”表达式的JOIN也称为CROSS JOIN。 根据文档,您无法使用查询构建器
执行此操作仅限内,左,右。
你只需要一个原生查询:
$connection = $em->getConnection();
$statement = $connection->prepare("
select t1.id, t2.id from table1 t1 join table2 t2
");
$statement->execute();
$results = $statement->fetchAll();
或者想更多地了解你想要收到什么