Content type: a standard page with Image field (unlimited values)
I created a view which should display only image and its name. Filename is in file_managed, so I created a relationship to File and added the File Name field. So there are two fields in the view: Image and File Name. The view uses Grid display and has unchecked "Display all values in the same row" for Image field to better illustrate the issue (without unchecking the isue still exists, only looks more strange)
Issue: instead of 3 images, there are 9 images displayed, because each image is repeated 3 times. That's because the LEFT JOIN with file_managed table is missing an additional condition:
AND (field_data_field_image.field_image_fid = file_managed_file_usage.fid)
If you add the above condition (in WHERE clause) then there is one-to-one relation between each image and its name and there are 3 images displayed (tested directly in database, because I don't know how to have Views use the additional restriction.
Is it possible to somehow insert such additional restriction to a View?
Attached screenshot and view
P.S. I was using Media to insert the images to the node, but I think the same happens without Media module, using just plain Image
Comments
Comment #1
couturier CreditAttribution: couturier commentedI believe that you would be able to fix the duplicates problem by correctly configuring the View in the UI. If you need more assistance, please update this issue with your current problem.
Comment #2
IWasBornToWin CreditAttribution: IWasBornToWin commentedWould you mind displaying the correct way in which you believe it can be fixed?
Comment #3
couturier CreditAttribution: couturier commented@IWasBornToWin can you please tell me the specifics of your Views setup? The issue described by raincloud is complex and may not apply to you personally.
Comment #4
IWasBornToWin CreditAttribution: IWasBornToWin commentedMine was a taxonomy related to nodes issue. I solved it by choosing "distinct" in query settings.
Comment #5
couturier CreditAttribution: couturier commentedExactly. You can use "distinct," you can use "reduce duplicates" in the filter criteria. There are several ways to configure things. Also, some people have noted bugs in the 7.x-3.5 Views release that make the published filters or sort criteria return duplicates. We're still working on that, but you can play around with removing various things to see what does and does not create duplicates if you still have issues. Once Drupal 8 is released, then we'll start all over with the duplicates question, I am sure.
Comment #6
cbrasfield CreditAttribution: cbrasfield commentedI have a relationship set with a taxonomy term that filters by a value within a multi-value field. It returns all of the values of the field for which the result is found. Distinct does not work.
Comment #7
couturier CreditAttribution: couturier commentedI really think it is a bug that has not been fixed yet. It appears to have started upon upgrade to 7.x-3.5. I had to simplify my Views for now to get things working again. Follow the progress at this issue: Duplicate rows are in the view's result set (was: distinct doesn't work)
Comment #9
lykyd CreditAttribution: lykyd commentedI had the same problem using a relationship on a classic cck field. The field was multiple so it caused duplicates in my view result. Finally I solved the problem by setting an option I had never noticed.
In Relationships, I clicked on my relation item and there's a "Delta" option in the edit. I set it to "1" because I only need to get the first Image (my multiple field content is an image). That killed duplicated results, but it works because I just need to get one of all pictures.
Comment #10
DeNelo CreditAttribution: DeNelo commentedI have a similar problem (running Views 3.6).
My Content type has a list of files, and I list those files. I add relationship to "File", and I add Filesize to the field list.
I then get every combination of filename and filesize (each filesize of each file in the list is repeated with each filename).
I have chosen Distinct (and True Distinct). I've also tried appliying the workaround in #8, but no luck so far.
Comment #11
Mołot CreditAttribution: Mołot commentedI'm currently working on making views able to understand many-fields joins in http://drupal.org/node/1966328
If this is done, you could build your bugfix on top of mine.
Comment #12
hachesilva CreditAttribution: hachesilva commented#6 by @pthurmond works like a charm, thanks for this. I was going nuts with the duplicates, almost 2 days gone trying to workaround this issue.
Comment #13
lovecookie CreditAttribution: lovecookie commented#8 by pthurmond worked for me as well, Drupal 7. Thank you!!!
Comment #14
MO-2 CreditAttribution: MO-2 commentedThis might help others:
https://drupal.org/project/views_distinct
Comment #14.0
MO-2 CreditAttribution: MO-2 commentedPS
Comment #15
kkalaskar CreditAttribution: kkalaskar commentedsame problem here.
I set In view->query settings, i have set it to distinct.
and it resolve.
Comment #16
谢艳 CreditAttribution: 谢艳 commentedTry various methods, finally #14 works for me
Comment #17
MXT#14 is the only method that resolves for me also
Comment #18
Gik000 CreditAttribution: Gik000 commented#8 worked for me ...
nice job!
Comment #19
raffi CreditAttribution: raffi as a volunteer commented#8 thanks
Comment #20
mocasalter CreditAttribution: mocasalter as a volunteer commented#14 worked for me, thanks!
Comment #21
C.E.A CreditAttribution: C.E.A commentedHere are workaround solutions:
1) In the Pager section:
Use pager:Display a specified number of items | 1 item
or
2) under advanced section, goto: Query settings and check the box distinct
0r
3) you can use "reduce duplicates" in the filter criteria.
or
4) You can try this module: https://drupal.org/project/views_distinct
Comment #22
AndraeRay CreditAttribution: AndraeRay as a volunteer commentedThanks #21!
I'm using query settings distinct. It warns about performance implications, but l haven't seen any noticeable difference.
You can see how long your query takes to run by going to views settings and enabling "Show performance statistics". This can help you to compare.
Comment #23
laura.gatesI believe that I've found another workaround that might come in handy:
In my view (D7 views v: 7.x-3.16)., I wanted to Display all values in the same row using a relationship to an entity reference. However, even with Query settings > Distinct selected I was still getting duplicates. Turning on aggregation removed the ability for my data to Display all values in the same row but also removed my duplicates.
So upon reading:
(and probably a few others that I missed)
I decided to try the NID and Count that was presented in https://www.drupal.org/node/603868#comment-4421144 but with a few extra steps....
I made the relationship that caused my duplicates required. Then added
NID
.NID
was then ranked 1st in field order. Turned aggregation on and changedNID
to count. This threw off the display of mybody
field so I had to changeBody
group column needs to be set tovalue
.summary
andformat
must be selected under *group columns (additional).Once these steps are complete, turn OFF aggregation and the duplicates were removed.
Comment #24
renatog#21 really makes sense
Thanks @C.E.A
Comment #25
renatogComment #27
dovlijaner CreditAttribution: dovlijaner as a volunteer and commentedDistinct doesn't work for me,. but works if I set "delta" in relationship like in #9
Comment #28
Lukas von BlarerI have a dirty hack for D8: https://gist.github.com/luksak/0907196a41315b5876f9d630a554f41c
It won't work with pagination an might cause unexpected issues, but in my case it solves the issue.