0

给定下面的查询,我可以得到一个结果集,其中包含查询中列出的位置 id 并按日期排序的所有新故事。我不明白的是如何重写查询,以便将每个位置 ID 限制为 1 个结果(最新)。

是否可以这样做,或者我应该在之后处理结果集?

提前致谢,

SELECT node.title AS node_title, node.nid AS nid, node.created AS node_created
FROM 
{node} node
INNER JOIN {field_data_field_story_location} field_data_field_story_location 
ON node.nid = field_data_field_story_location.entity_id 
AND (field_data_field_story_location.entity_type = 'node'
WHERE (( (node.status = '1') AND (node.type IN  ('_news_story')) 
AND (field_data_field_story_location.field_story_location_tid IN  
('38', '44', '46', '45', '30', '36', '37', '29', '33', '34', '28', '56', '21', '49', '32')) ))
ORDER BY node_created DESC
4

1 回答 1

2

您可以在之后处理结果集,但在大量数据的情况下效率不高。

为了提高效率,您可以编写 n 个查询(每个 field_story_location_tid 一个),限制为 1,然后使用UNION sintax加入结果集

于 2013-05-07T10:31:51.133 回答