Duplicate View results when sorting by weight_in_tid

Oliver Coleman - September 28, 2009 - 23:54
Project:nodeorder
Version:6.x-1.0
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I'm using a View (overriding the default taxonomy/term/tid View) to display nodes ordered by node order.

Nodes that are assigned to two terms appear twice when viewing those term pages. If I remove one of those terms the duplicates go away.

The View is set to sort by weight_in_tid (and nothing else); Distinct is set to "yes" for the View. If I remove the weight_in_tid sort criteria the duplicates go away.

This only occurred after an upgrade from D5 to D6 (D5 site used the same nodeorder and views setup, but without this duplicates in views issue).

The SQL for the view is (term ID in this example is 60):

SELECT DISTINCT(node.nid) AS nid,
   term_node.weight_in_tid AS term_node_weight_in_tid
FROM node node
LEFT JOIN term_node term_node ON node.vid = term_node.vid
WHERE (node.status <> 0 OR (node.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0) OR ***ADMINISTER_NODES*** = 1) AND (node.vid IN (
  SELECT tn.vid FROM term_node tn
  WHERE tn.tid  = 60
  ))
   ORDER BY term_node_weight_in_tid ASC

merlinofchaos of Views has said that he's found distinct to be unreliable in mysql (we're using version 5.0.51a on a standard Debian install). I posted the issue in the Views issue queue initially but merlinofchaos says it should be posted here.

#1

lop - October 5, 2009 - 22:33

I think this is the Views issue. There must be something wrong in sql rewrites for sorting with taxonomy data.
Try changing the sort criteria from weight_in_tid to something more general like Taxonomy: TermID and there are duplicates too. And it doesn't matter if you use DISTINCT or not.

I had the same problem until I changed the Arguments from Taxonomy: TermID (with depth) to Taxonomy: TermID and the duplicates are gone. (if you don't need the 'depth' parameter, of course)

#2

matteo.boria - October 9, 2009 - 15:00

Not really an issue, but: this is a problem, for sure.
A possible solution:
http://drupal.org/node/345571#comment-1188223

Ciao;
Matteo

 
 

Drupal is a registered trademark of Dries Buytaert.