zend_db_select 使用 3 个或更多表进行连接

发布于 2024-10-16 04:28:43 字数 465 浏览 3 评论 0原文

所以 Zend_db_select 有方法

  `joinUsing(table, join, [columns]) and joinInnerUsing(table, join, [columns])`

  `joinLeftUsing(table, join, [columns])`

  `joinRightUsing(table, join, [columns])`

  `joinFullUsing(table, join, [columns])`

等,

但是如果你想连接 3 个或更多表(例如,多对多关联)怎么办......例如:这个查询:

 SELECT * FROM (j LEFT JOIN e ON j.id = e.eee) LEFT JOIN w ON w.www = e.id

你会如何用 zend_db_select 来做到这一点

So Zend_db_select has the methods

  `joinUsing(table, join, [columns]) and joinInnerUsing(table, join, [columns])`

  `joinLeftUsing(table, join, [columns])`

  `joinRightUsing(table, join, [columns])`

  `joinFullUsing(table, join, [columns])`

etc

but what if you want to join 3 or more tables (eg for a many to many association)....eg: this query:

 SELECT * FROM (j LEFT JOIN e ON j.id = e.eee) LEFT JOIN w ON w.www = e.id

how would you go about doing this with zend_db_select

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧竹 2024-10-23 04:28:43

尝试做...但我不太确定是否可以使用两个字段,但还没有尝试过使用

$dbmodel->select(false)
    ->setIntegrityCheck(false)
    ->from(array('t1' => 'table1'))
    ->joinLeft(array('t2' => 'table2'),                                             
        't1.somefeild = t2.somefeild')
    ->joinLeft(array('t3' => 'table3'),                                             
        't2.somefeild = t3.somefeild')

您尝试构建查询的3个字段,并且您也可以通过 die((string)$select) 检查查询

Try doing ... but i am not so sure works with two fields but have not tried with 3 fields

$dbmodel->select(false)
    ->setIntegrityCheck(false)
    ->from(array('t1' => 'table1'))
    ->joinLeft(array('t2' => 'table2'),                                             
        't1.somefeild = t2.somefeild')
    ->joinLeft(array('t3' => 'table3'),                                             
        't2.somefeild = t3.somefeild')

you try to build query, and also you can check query by die((string)$select)

深巷少女 2024-10-23 04:28:43

尝试使用子查询和 Zend_Db_Expr。点击此处了解更多信息。

Try use subquery and Zend_Db_Expr. Read more here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文