【问题标题】:Exception Join in Zend\Db 2.8.2 (DB2)Zend\Db 2.8.2 (DB2) 中的异常连接
【发布时间】:2018-04-10 21:13:41
【问题描述】:

我似乎不知道如何使用 Zend\Db 创建异常连接?

我看到明确的support 表示内、外、左、右、右外和左外。但希望仍有办法保留抽象。

是唯一的使用方式:

$db->query('Select * from...exception join....')

【问题讨论】:

  • 请确认您的确切 Db2 版本和运行 Db2 服务器的操作系统。 “Db2 for i”支持异常连接语法,但 LUW 或 Z/OS 上的 Db2 在当前版本中不支持,因此对于这些环境,NOT EXISTS 子查询可以提供帮助。
  • 它是 DB2 for i,但我已经知道如何在 DB2 for i 中创建异常联接。我更感兴趣的是如何使用 Zend/Db 创建异常连接(或等效连接),同时利用它提供的抽象层。我只是想避免对 SQL 语句进行硬编码。

标签: zend-framework2 db2 zend-db db2-400


【解决方案1】:

您可以使用外部联接模拟异常联接,其中联接右侧的行缺失。例如:

select a.id, a.description, b.name
  from table1 a
    left exception join table2 b 
      on a.id = b.id

相当于:

select a.id, a.description, b.name
  from table1 a
    left outer join table2 b 
      on a.id = b.id
  where b.id is null

我现在无法对此进行测试,但根据 documentation,您应该可以执行以下操作:

$select = new Select();
$select->columns(array('id', 'description'));
$select->from(array('a' => 'table1'));
$select->join(
    array('b' => 'table2'),
    'b.id = a.id',
    array('name'),
    $select::OUTER
);
$select->where(array('b.id' => null));

【讨论】:

  • 谢谢,我不敢相信我没有想到这一点。异常连接上的隧道愿景,而不是考虑逻辑等价物......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多