具有多个表连接的 Zend DB Select [英] Zend DB Select with multiple table joins

查看:31
本文介绍了具有多个表连接的 Zend DB Select的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用 Zend_Db_Select 复制以下查询.有什么指点吗?

Trying to replicate the following query using Zend_Db_Select. Any pointers?

SELECT 
  compounds.id as compounds_id,
  reactions.id as reactions_id, 
  reaction_compound.number as reaction_compound_number  
FROM compounds, reactions, reaction_compound 
WHERE  
  compounds.id IN (68,74,112) 
  AND compounds.id = reaction_compound.compound  
  AND reactions.id = reaction_compound.reaction;

特别是我遇到的一些问题是在 Zend 中执行多个表连接.我不确定如何使用他们的查询构建器跨多个表进行连接.

Specifically some issues I'm running into are doing multiple table joins in Zend. I'm not sure how to do the join across multiple tables using their query builder.

感谢任何帮助!

J

推荐答案

诸如此类:

$compoundIds = array(68,74,112);
$select = $db->select()
   ->from('compounds', array('compounds_id' => 'id')
   ->where('compounds.id in ( ? )', $compoundIds)
   ->join('reaction_compound', 'compounds.id = reaction_compound.compound', array('reaction_compound_number' => 'number'))
   ->join('reactions', 'reactions.id = reaction_compound.reaction', array('reaction_id' => 'id');

那应该可以带你到某个地方.我没有测试过,所以可能有一些错误.

That should get you somewhere. I didn't test it, so there might be some errors in there.

这篇关于具有多个表连接的 Zend DB Select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆