ExpressionEngine查询结果在另一个查询中

时间:2014-06-15 04:34:33

标签: mysql expressionengine

我有两个问题。我希望一个查询的结果是另一个查询的IN。我今天尝试了很多解决方案,包括PHP(需要一个解析输入和一个解析输出,所以它不起作用),它只是不起作用。有没有办法实现这个目标?

{exp:query sql="SELECT DISTINCT parent_id FROM exp_relationships WHERE child_id = {entry_id} AND grid_field_id IN (90, 91, 112)" backspace="2"}{parent_id}, {/exp:query}
{exp:query sql="SELECT field_id_16 AS firstyear FROM exp_channel_data WHERE entry_id IN ('RESULTSHERE') ORDER BY firstyear ASC LIMIT 1"}
    {exp:ce_str:ing truncate="4||yes"}{firstyear}{/exp:ce_str:ing}
{/exp:query}

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以将查询放在另一个的IN子句中:

SELECT field_id_16 AS firstyear 
FROM exp_channel_data 
WHERE 
  entry_id IN (
    SELECT DISTINCT parent_id FROM exp_relationships WHERE child_id = {entry_id} AND grid_field_id IN (90, 91, 112)
  ) 
ORDER BY firstyear ASC LIMIT 1