Here's what I have...
1) I have a custom content type, "business". Within that content type I have some CCK fields. One of those fields is "biz_type" and lists multiple categories of businesses.
2) I created a views block to list all business types based on the content type business. I query and list only this "biz_type" CCK field. I want to list all the business types where there are current records. These link to another view that will display all the businesses of that type.
Problem:
When I have more than one business in a single type, it lists the "biz_type" field twice even though it is exactly the same. I have used the "Group multiple values" handler when defining the queried fields. No change.
Example:
Dry Cleaner
Pizza
Pizza
Retail
Ideas? Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | views-select-distinct-0.patch | 559 bytes | Cybso |
Comments
Comment #1
CMatters commentedComment #2
Cybso commentedTry to modify views_query.inc. In line 654, change "SELECT $fields..." into "SELECT DISTINCT $fields...". This should work in table view. I'm not quite sure if this patch produces some side-effects, but I think "SELECT DISTINCT" is the natural expected behaviour.
Comment #3
domesticat commentedPerforming a mass closing of all issues over 180 days old. Please reopen if needed.
Comment #4
Alun commentedThis is a still a problem and I have need to sort out a solution too.
Trying to show a list of Artists on a store where I am selling thousands of records. I just want to display a distinct list of the artists and then link them to go to another view showing their records. When using views, it will print out the same artists name multiple times, if I have, for example, 10 records by the same person.
Comment #5
Alun commentedI have implemented a custom module that, for now will solve the issue for myself.
It probably is a bad way of doing things, as I am a beginner at Drupal.
I have used hook_views_pre_render to catch the fields before they are printed out and qiuckly removed all duplicate values in the easiest way I could using a simple for loop.
This code requires that you have your fields sorted alphabetically and are only displaying one field. (thats how I differentiated it from my other views)
Comment #6
Alun commentedComment #7
Alun commentedSince writing the above code, I changed it slightly and have been playing about with hook_views_query_alter.
Unfortunately, I can't figure out how to add the "GROUP BY" into the SQL using this hook - doing so will sort me out and give a clean solution to this problem.
Any ideas?
Comment #8
Alun commentedI have found out more after scouring the web! It seems this is a common problem.
http://groups.drupal.org/node/18277
The above discussion revealed that using hook_views_query_alter used to work.
Views 2.3 broke that, so I have raised this as an issue in the views forum.
I am currently living with Views 2.2 until I know the problem is resolved.
My issue is here
http://drupal.org/node/624646
Comment #9
Alun commentedAfter being told the views problem is by design, I hacked the problem myself after playing around in query.inc
In the current views version, (2.7, drupal 6) on line 984, I replaced the line
$groupby = "GROUP BY " . implode(', ', array_unique(array_merge($this->groupby, $non_aggregates))) . "\n";with
$groupby = "GROUP BY " . implode(', ', array_unique($this->groupby)) . "\n";Which allowed me to create a custom module that used hook_views_query_alter to add my group by clause without any problems! I think it goes against some things, but it works for my website, which is what I was looking for!
Comment #10
Alun commentedFor anyone with this problem, here is my custom module code - my module is called distinctviews.
The code from distinctviews.module is here
Comment #11
drupal3008 commentedI think you don't have to modify you can just use arguments.
See #2 at http://drupal.org/node/478696
(originally mine, didn't see this OP - sorry for the duplicate!)