gpt4 book ai didi

php - Inner Join WITH 和 inner join ON 有什么区别?

转载 作者:行者123 更新时间:2023-11-30 23:03:12 27 4
gpt4 key购买 nike

阅读 Doctrine 2 文档时 at this page我可以看到他们有两种方法来指定内部连接的条件:

// Example - $qb->expr()->innerJoin('u.Group', 'g', Expr\Join::WITH, 'g.manager_level = 100');
// Example - $qb->expr()->innerJoin('u.Group', 'g', 'WITH', $qb->expr()->eq('g.manager_level', '100'));
public function innerJoin($join, $alias, $conditionType = null, $condition = null); // Returns Expr\Join instance

// Example - $qb->innerJoin('u.Group', 'g', Expr\Join::ON, $qb->expr()->and($qb->expr()->eq('u.group_id', 'g.id'), 'g.name = ?1'))
// Example - $qb->innerJoin('u.Group', 'g', 'ON', 'u.group_id = g.id AND g.name = ?1')
public function innerJoin($join, $alias = null, $conditionType = null, $condition = null);

我不明白其中的区别,因为 innerjoin 仅在找到匹配项时才返回内容,而且我找不到任何关于此的文档。

谢谢

最佳答案

看起来它们是同义词。基于 Doctrine EBNF 表达式(在 http://docs.doctrine-project.org/en/2.0.x/reference/dql-doctrine-query-language.html#from-join-and-index-by 找到),Doctrine 似乎更喜欢 WITH。然而,MySQL(可能还有其他 SQL 数据库)使用 ON,所以我猜测 Doctrine 的作者包含了该表达式以避免混淆他们的用户。

Doctrine 的开发者已经编写了他们自己的 SQL 变体——这是因为 Doctrine 是一个对象关系管理器(ORM),而不是一个直接的查询构建器。他们的 SQL 变体旨在与他们的对象一起工作。所以,例如,如果你正在构建 usergroup 模型并想表达它们之间的关系,你可以用 Doctrine 的查询语言来做,它会处理JOIN 条件自动发生。

关于php - Inner Join WITH 和 inner join ON 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23023660/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com