CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Drupal 7 view 3 Field being adding when adding Distinct
Pages: [1]

Author Topic: Drupal 7 view 3 Field being adding when adding Distinct  (Read 2798 times)

pamreed

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.04
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.3
Drupal 7 view 3 Field being adding when adding Distinct
July 30, 2011, 06:27:05 pm
Hi 

I am using Drupal 7.4 and CiviCRM 4.0.4 with Views 3.0-rc1.  I need a distinct list of cities from the Civicrm contacts. So create view select civicrm contacts table and did the following to the view.
 1. Add the Civicrm Address City field
 2. Removed the Contact Id field.
 3. Add Filter Criteria of Location Type and Membership Type and Member Status
All looks good in with the SQL just he civicrm_address.city  not contact_id:
   
SELECT civicrm_address.city AS civicrm_address_city
FROM
{civicrm_contact} civicrm_contact
LEFT JOIN {civicrm_address} civicrm_address ON civicrm_contact.id = civicrm_address.contact_id
LEFT JOIN {civicrm_membership} civicrm_membership ON civicrm_contact.id = civicrm_membership.contact_id
WHERE (( (civicrm_address.location_type_id IN  ('6')) AND (civicrm_membership.membership_type_id IN  ('1', '2')) AND (civicrm_membership.status_id IN  ('1', '2', '3')) ))
ORDER BY civicrm_address_city ASC

4. Now add the Query Settings: Distinct
  It adds the civicrm_contact.id to the sql.  So, now not getting the distinct list of cities because of the field being adding.

SELECT DISTINCT civicrm_address.city AS civicrm_address_city, civicrm_contact.id AS id
FROM
{civicrm_contact} civicrm_contact
LEFT JOIN {civicrm_address} civicrm_address ON civicrm_contact.id = civicrm_address.contact_id
LEFT JOIN {civicrm_membership} civicrm_membership ON civicrm_contact.id = civicrm_membership.contact_id
WHERE (( (civicrm_address.location_type_id IN  ('6')) AND (civicrm_membership.membership_type_id IN  ('1', '2')) AND (civicrm_membership.status_id IN  ('1', '2', '3')) ))
ORDER BY civicrm_address_city ASC

Why is the civicrm_contact.id being added? It is not necessary. I am missing a different way to get a distinct list of all the cities contact member is in?

Any help would be greatly appreciated. Let me know if more information is need.

Thank you,
Pam






Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Drupal 7 view 3 Field being adding when adding Distinct
July 31, 2011, 06:10:37 am
civicrm_contact.id is the primary result. You chose "CiviCRM Contacts" as the basis for this view, thus each row is based on a contact. I'm not sure if it's possible to do what you want with Views, but perhaps using Grouping you could.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Drupal Modules (Moderator: Donald Lobo) »
  • Drupal 7 view 3 Field being adding when adding Distinct

This forum was archived on 2017-11-26.