Mysql DISTINCT and ORDER BY not working

I have this query:

    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

So I want to get items with unique guids and want to order it by '_updated' field from 'metricts_default' table. But nothing happens. If I delete DISTINCT() - result is fine, but with duplicates.

Upvotes: 0

Views: 224

Answers (1)

ideoutrea
ideoutrea

Reputation: 199

you misunderstand the distinct keyword distinct here does not mean you will get distinct entries.guid, but different row

what this mean is the row with same guid but different In other fields will not be eliminated by MySQL.

Upvotes: 1

Related Questions