【发布时间】:2018-06-19 14:31:35
【问题描述】:
我有这个问题:
SELECT
DISTINCT (entries.guid),
locales.*,
locales.guid as locale_guid,
entries.*,
node.category_guid,
node.title as node_title,
nodelocs.caption as node_caption,
nodelocs.uri as node_uri,
nodelocs.url as node_url
FROM entries AS entries
JOIN entry_locales AS locales ON (locales.entry_guid=entries.guid)
LEFT JOIN nodes AS node ON (node.guid=entries.node_guid)
LEFT JOIN node_locales AS nodelocs ON (nodelocs.node_guid=entries.node_guid AND nodelocs.lang_guid=locales.lang_guid)
LEFT JOIN metrics as metrics_default ON (entries.guid = metrics_default.entry_guid)
WHERE
metrics_default.customer_guid='453b894967968204'
AND metrics_default.metrics='entryview'
AND locales.lang_guid='4b5747548a5bd457'
AND locales.state='1' AND entries.node_guid IN (SELECT child_guid FROM node_children WHERE guid IN ('4b084f280caffbef') ) ORDER BY metrics_default._updated DESC LIMIT 0,10
所以我想获取具有唯一 guid 的项目,并希望通过 'metricts_default' 表中的 '_updated' 字段对其进行排序。但什么也没有发生。 如果我删除 DISTINCT() - 结果很好,但有重复。
【问题讨论】:
-
distinct 不是列上的函数。它适用于所有被选中的列。
标签: mysql select sql-order-by distinct