[英]Multiple column in IN() clause with zend framework
Is it possible to do this sort of query in zend frameowrk? 是否可以在zend frameowrk中进行此类查询?
SELECT *
FROM `relations`
WHERE (root_type, root_id) IN ( ("PRJ", 12), ("PRJ", 13), ("GRP", 42))
I only found a way to make a query with a IN clause on one column but not on two columns. 我只找到了一种方法,在一列上使用IN子句但不在两列上进行查询。
You can JOIN
them instead, like this: 您可以改为
JOIN
它们,如下所示:
SELECT r.*
FROM relations r
INNER JOIN
(
SELECT 'PRJ' AS root_typ, 12 AS root_id
UNION ALL
SELECT 'PRJ', 13
UNION ALL
SELECT 'GRP', 42
) AS t ON r.root_type = t.root_type
AND r.root_id = t.root_id;
This is a ZF1 query using Zend_Db_Statement : 这是使用Zend_Db_Statement的ZF1查询 :
//common way to aquire currently selected db adapter
$db = Zend_Db_Table::getDefaultAdapter();
//$db is the currently selected database adapter.
$stmt = $db->query(
SELECT * FROM `relations`
WHERE (root_type, root_id)
IN ( ("PRJ", 12), ("PRJ", 13), ("GRP", 42))
);
This answer is not intended to be snide. 这个答案并不是为了讽刺。 For complex database queries,
Zend_Db_Statement
is often the easiest/simplest/best way to perform the query. 对于复杂的数据库查询,
Zend_Db_Statement
通常是执行查询的最简单/最简单/最好的方法。
If you would like an explanation more tailored to your needs, please provide more info on your structure. 如果您想要根据您的需求量身定制解释,请提供有关您的结构的更多信息。 In Zend Framework (1 or 2) there are often many ways to accomplish any given task.
在Zend Framework(1或2)中,通常有许多方法可以完成任何给定的任务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.