mysql distinct并按不工作排序

vngu2lb8  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(426)

我有个问题:

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\u default”表中的“\u updated”字段排序。但什么也没发生。如果我删除distinct()-结果很好,但有重复项。

blmhpbnm

blmhpbnm1#

您误解了distinct关键字distinct并不意味着您将获得distinct ENTRYS.guid,而是不同的行
这意味着具有相同guid但在其他字段中不同的行不会被mysql消除。

相关问题