I have this mysql query for Drupal 6. However it doesn't return distinct nid as it is meant to be. Can someone help identify the bug in my code?
SELECT DISTINCT( n.nid), pg.group_nid, n.title, n.type, n.created, u.uid, u.name, tn.tid FROM node n
INNER JOIN users u on u.uid = n.uid
LEFT JOIN og_primary_group pg ON pg.nid=n.nid
LEFT JOIN term_node tn ON tn.vid=n.vid
WHERE n.nid IN (
SELECT DISTINCT (node.nid)
FROM node node
INNER JOIN og_ancestry og_ancestry ON node.nid=og_ancestry.nid
WHERE og_ancestry.group_nid = 134 )
AND n.status<>0
AND n.type NOT IN ('issue')
AND tn.tid IN (
SELECT tid FROM term_data WHERE vid=199 AND ( LOWER(name)=LOWER('Announcement') OR LOWER(name)=LOWER('Report') OR LOWER(name)=LOWER('Newsletter')
)) ORDER BY n.created DESC
The only way I can get distinct nid is adding a groupby clause but that breaks my Drupal pager query.
DISTINCT is meant to return the DISTINCT row selected, so not a single column as part of the select clause, but the ENTIRE select clause.
The ALL and DISTINCT options specify whether duplicate rows should be returned. ALL (the default) specifies that all matching rows should be returned, including duplicates. DISTINCT specifies removal of duplicate rows from the result set. It is an error to specify both options. DISTINCTROW is a synonym for DISTINCT.
0 comments:
Post a Comment