Closed (won't fix)
Project:
Views (for Drupal 7)
Version:
6.x-2.6
Component:
Views Data
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Anonymous (not verified)
Created:
11 Dec 2008 at 04:51 UTC
Updated:
16 May 2024 at 00:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
Anonymous (not verified) commentedSorry, I should rephrase:
I'm getting duplicate nodes in my view due to some nodes having more-than-one taxonomy term.
Example:
In this case, the different airlines are taxonomy terms.
Comment #2
merlinofchaos commentedI can't help without an export of the view, as I have no idea how it's configured.
Comment #3
Anonymous (not verified) commentedRight, here you go then...
(Thought I'd attach it, rather than paste it here)
Oh, and by the way, the example I posted above doesn't match up with the fields in the export as I deleted some values that weren't necessary.
Comment #4
aleagi commentedHi,
I'm having the same problem here. In fact I was studying the problem and have customized a simple view to better presentation of the problem.
In the attached view there's only the NID (to be sure that the node is repeated), the Node Title and the Taxonomy Term Field.
Yes, I've also checked the Distinct on the Basic Configuration. The problem is that the view is, even with the checked box, showing duplicated nodes.
Nothing wrong until now...
The problem, in my point of view, is located on the Distinct, that is not distincting nothing at all. I mean, even with the distinct function enabled, the nodes are still being duplicated, one for each taxonomy term.
Is it possible to have, again, the Node: Distinct Filte?!? It seems to work better than the present one. Or, if needed, to add the filter AND the distinc on basic configuration block, just to guarantee that the node will be showed only once.
I mean, a redundant option (not so redundant as the first option are not working as we expected) like a: Reduce multi-terms repetitions or something.
Thanks in advance, Any help will be appreciated!
Comment #5
Anonymous (not verified) commentedAny updates on this? Solutions?
Comment #6
merlinofchaos commentedYou should be using the "Taxonomy: All terms" field if you can have multiple terms on a node. In the field options you can restrict which vocabulary you want the terms to appear from.
Comment #7
Anonymous (not verified) commentedYay! Thanks Merlin!
Comment #8
superhua commentedThank you!
Is there anyway to display the multiple _descriptions_ of the taxonomy terms without causing duplicates?
That is, is there anything like a "Taxonomy: All terms' descriptions" field?
Comment #9
merlinofchaos commentedUnfortunately there is not.
Comment #11
lizbethalml commentedHello merlinofchaos! first of all thank you so much!!! this is a great module!!!!!!! that is a good solution... the one of taxonomy all terms but what I want to displan is the taxonomy image! so is there a way to do this from here? cause I don't want to cause duplicates... thank's again!
Comment #12
bloke_zero commentedIf you can't restrict yourself to one vocabulary for any reason (say you need more than 1!) you can still get there by using the node view and theming the node (in my case a product) and having different displays depending on whether it was a teaser or full node view and print a few of the fields in the teaser view rather than the whole lot.
I found using the fields display in the view useless as it allowed duplicates to appear, but using the node view (with 'Distinct' set to yes) and the theming worked.
And yes, thank you for a wonderful module! Drupal would be infinitely poorer without it.
Comment #13
patchak commentedI have the same problem using views 6.x-2.2
I'm not using "fields" I'm only using the "node" style to make a view that replicates the core "taxonomy/term" view. I still have duplicate nodes each time I have nodes that are tagged in several categories. How can I fix this if I don't use fields as the type?
I tried setting on the "Distinct" setting, but it does not seem to have had any effect...Any ideas?
thanks a lot
Patchak
Comment #14
borfast commentedI am also having the same problem of having a node instance per each taxonomy term associated with it.
I have the distinct option enabled and have even cleared everything on the view except for the node title and taxonomy term fields - I still get duplicates (not that I thought that clearing everything would help in not getting duplicates; I just wanted to get a simpler SQL query to look at).
My use case is that I am using the Taxonomy Image module, which provides a "term image" field that causes exactly the same problem as the "taxonomy term" field - one node instance per each term.
The resulting query is quite simple:
I'm a bit rusty with SQL but I checked it and confirmed that this does indeed produce multiple rows for the same node - and we need this, otherwise we couldn't get the various taxonomy terms associated with the node.
So, as I said, I'm a bit rusty on SQL but I'm assuming the SQL code and its result set is correct, which leaves us with the problem being somewhere in the Views code that handles and displays the results.
My guess (I grepped and searched through the code but I know next to nothing of the internal workings of Views, so I may have missed it) is that Views is only using the Distinct option to generate the SQL code but in cases such as the one I presented above, it does nothing to merge the multiple results.
If that's the case, what would be the best way to fix this?
Comment #15
borfast commentedComment #16
dawehnerDid you really read this issue, there is the solution :)
http://drupal.org/node/345571#comment-1188223
Comment #17
borfast commenteddereine, that's not quite the solution, since I was already doing that and still get duplicate terms. Perhaps I didn't explain myself well but the problem is that the result set contains several nodes with the same id (effectively, the same node) even if I limit the terms to one vocabulary.
The node type I'm selecting doesn't even have any other vocabulary associated with it.
In other words, the resulting list shows the same node several times - one entry for each term associated with it - even if I restrict the vocabulary selection and/or check the "reduce duplicates" option.
Comment #18
vthirteen commentedi guess i have the same problem.
i'm filtering by node type, these nodes are tagged with single terms from two different vocabularies. incidentally, i have a "taxonomy: ID term with depth" exposed filter with "reduce duplicates" checked, plus the same taxonomy is also used as an argument (i need both ways of "filtering" content).
then i have a "Taxonomy: all terms" field with terms limited to just one vocabulary.
still, i have duplicate nodes in the views listing, that is nodes tagged with terms from more than one vocabulary appear twice.
the export of my view is attached.
Comment #19
vthirteen commented[set it to active again even though i'm not sure if in my case it's not just a matter of wrong configuration]
Comment #20
vlooivlerke commentedI have the same problem.
Multiple tags, cause multi node displays.
Comment #21
giorgoskNOTE:
"taxonomy term" fields will cause duplicates of nodes that have multiple terms selected
use "taxonomy all terms" instead and only check the desired vocabulary to display
works as above with no duplicates and no need for filtering
but field is not sortable :-( ( << does anybody know of a workaround ?)
also NOTE: relationships on taxonomy terms will cause duplicates of nodes that have multiple terms selected
(delete these relationships if you don't really need them)
Comment #22
merlinofchaos commentedReduce duplicates will not remove duplicates due to having multiple terms on a node.
If you have multiple terms on a node, there is very little you can do to show data about that term without ending up with duplicates. If you need multiple taxonomy images, then taxonomy image will need to provide a field similar to taxonomy: All terms to show the images.
In fact, anything you do that attempts to add a particular field (or sort or filter) from a term is going to cause these duplicates. These are not bugs that is the natural behavior of SQL.
Comment #23
dzieyzone commentedI was also having the same problem and to found out that it is indeed how the views was created:
The views created:
The DISTINCT(node.nid) is really useless because of the term_node.weight_in_tid) AS term_node_weight_in_tid therefore when I re-write the views query into
By removing the term_node.weight_in_tid AS term_node_weight_in_tid in display and changing the ORDER BY term_node_weight_in_tid DESC to ORDER BY term_node.weight_in_tid DESC I was able to get a unique node items.
This means that adding additional field in the select ruins the query.
The fix I can think of is that the views should not include a field for those that are in sorted or filter options.
Comment #24
merlinofchaos commentedUnfortunately, Postgres (and thus ANSI SQL) requires that any item in the ORDER BY also be in the fields.
Comment #25
shashi_lo commentedI only need the Taxonomy title and nothing else, but here's the code I put in before the foreach
Comment #26
dvness commentedany clues on how to get this to work properly? i'm having the same issue - all terms associated with a node are displayed, but the node appears as many times as there are terms associated with it.
Comment #27
dawehnerSee http://drupal.org/node/345571#comment-2254238
Please take care that you have taxonomy: all terms instead of taxonomy:term as field.
Comment #28
weseze commentedI was having a similar problem.
Setup a view of nodes with 2 Taxonomy:term filters for 2 different vocabularies. Nodes with more then one term showed up more then once. With the combination of 2 vocabularies some nodes showed up 4 times and more... Simply selecting the distinct option solved my problem.
Comment #29
youssefr commented.......#6
Hi
How do you get to this option?
Thanks.
Comment #30
eric constantinides commentedI was just having this issue too. Using "distinct" had previously not worked either. I ended up installing the "Views related nodes" module and using the "reduce duplicates" within the "Taxonomy: Term ID" argument. And voila! Problem fixed.
Comment #31
zoo33 commentedJust a clarification or reiteration of what merlin says here: http://drupal.org/node/345571#comment-2544996
If you use taxonomy terms as a sort criterion and any of the matched nodes have more than one taxonomy term, you will end up with duplicates. Doesn't matter if you have a visible taxonomy field or not.
Comment #32
WildKitten commented@ shashi_lo : Thanks for this! It did trick for me :)
I had multiple terms from same vocabulary in one node.
In view I had this:
Filds: Node title.
Filters: Tahonomy Term (exposed).
So I made views-view-unformatted.tpl.php file for my view. And add your code in right place.
Comment #33
WildKitten commented#32 was good until I had to use pager. Pager was made based on original number of rows so it was wrong for new number of rows. So I did something else.
I had multiple terms from same vocabulary in one node.
In view I had this:
Filds: Content Photo.
Filters: Tahonomy Term (exposed).
So, unchecked "Group multiple values" for field that has multiple values (in my case it was Photo).
In custom module add this function:
That is all. Adding DISTINCT after SELECT in query removes all duplicate rows.
And
$view->build_info['count_query']=$view->build_info['query'];rebuild new pager for new query.Hope this will help someone.
Comment #34
fadgadget commentedThanks WildKitten. This is the same problem ive had for ages now. I just cant fix it. Ive only got 2 terms per node both in the same vocab on my frontpage view and i get duplicates. It's a bugger. Before i go on my voyage of drupal discovery over this is there really no other way to fix this? I thought Views could deal with more than one term at a time to make an easy enough display without duplicates. Could anyone tell me what i might need to change in a view to remove duplicates?
-Same vocab
-sorted by comment time
-no arguments or relationships.
-no tax image
Hopefully by the time i finish the rest of my site folks will know when ive got single entry posts on the latest page then i might be almost done lol
Comment #35
WildKitten commented@fadgadget : #33 works like a charm form me. Have you tried to do that? Also mu CCK field (Photo) has unlimited values.
Comment #36
doomed commentedZoo33 is right.
If you are filtering by taxonomy and also sorting by the same taxonomy, you are bound to have duplicates.
Comment #37
nally commentedA solution that I found worked well for me was to form a View not of nodes, but a View of taxonomy terms and then use a relationship to find all nodes with that term applied. Your mileage may vary.
Comment #38
japo32 commentedthank you!
Comment #39
pzula commentedHi Nally,
Can you describe this process a little? Does creating a view of taxonomy terms mean that your "fields" was set to "Content: all taxonomy terms"?
Comment #40
lykyd commentedMy problem was that I was using the 'taxonomy_term_data' (Taxonomy Term) instead of using the field that references the terms of the node 'field_data_field_article_tags' (Content) in my case.
Now I can use Distinct to remove duplicate results. I'm using a Node View.
Comment #41
akki123 commentedAfter five years
@dzieyzone : #23 is still the issue, but solution was not given.
A detail solution - http://drupal.stackexchange.com/questions/106422/why-does-views-add-the-sort-field-as-a-select-expression
So for query in #23 , hook_views_query_alter will be
Comment #42
millionleaves commentedI experienced this problem on my site. Hopefully my solution might help others with the same problem.
My solution was to add an Entity Reference relationship to the Catalogue vocabulary and use that to obtain the weight value for the term (I am using Entity Reference, not Term Reference). This allowed me to keep the grouping AND sort the terms by weight. I did not need to set the view to Distinct.
Comment #43
millionleaves commentedHere's another solution inspired by #33 (didn't work in D7) and #41 (not quite the solution I needed), with help from https://www.drupal.org/node/1565480#comment-10418017.
Essentially, it's a custom module that alters the view by adding a Group By nid clause to the query generated by the view.
This solved my problem.
Note that you need to specify the View and (optionally) the Display that you want to alter.
For reference, my problem was that I had a product catalogue where products could be assigned more than one term within the Catalogue vocabulary. These nodes would then appear more than once on each related Catalogue page. This module fixed that.
Comment #44
bloke_zero commented@millionleaves - looks like the right solution - neat. Thanks for sharing!
Comment #45
philsward commentedRan into this with Draggable views. Trying the suggestion about removing the weight sort filter, I removed the draggable views weight filter, re-added it and it appears to have fixed my duplicate problem.
Oddly, the duplicates were random. Some were duplicated, others were not and there was no rhyme or reason to it.
I guess the moral of the story is to create the proper contextual filter first, then add the weight? I spent 2 days off-and-on trying to find the "right" contextual filter only to now realize, it was (technically) a Views "bug" (design?) all along.