Answers.Body: <p>Make sure you select only the address where is_primary = 1</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-03T14:10:56.427Z
Answers.Text: OR filter by location type = home, billing, work etc .
Answers.UserDisplayName: jitendra - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-06T09:11:26.600Z
Answers.Text: This seems related to address revisions. The addresses may have been updated over time, for example changing the zip code, and for some reason the view is showing all of the revisions. How can I configure it to show only the current revision?
Answers.UserDisplayName: Brylie Christopher Oxley
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-06T09:30:54.430Z
Answers.Text: For what it's worth, we do want to display multiple address *types* on the view, but only the latest revision of each type.
Answers.UserDisplayName: Brylie Christopher Oxley
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-29T21:07:22.057Z
Answers.Text: Has anyone figured out how to only show the most recent address revision?
Answers.UserDisplayName: Zachary
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-03T10:45:35.607Z
Answers.LastActivityDate: 2017-06-03T10:45:35.607Z
Answers.UserDisplayName: ErikH - CiviCooP
Answers.Body: <p>If you are still having trouble after setting DISTINCT as an option in the View, and specifying the Location Type hasn't helped -- then a RANDOM sort order may be the issue. Because of the way Drupal views handles random as a column as well as a ORDER BY clause, it breaks the distinctness of the query.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-23T17:25:59.933Z
Answers.LastActivityDate: 2020-04-23T17:25:59.933Z
Answers.UserDisplayName: CiviTeacher
Answers.Body: <p>If you can't sort the above out by ensuring you specify Location type (ie have a field for Zip = Worship, as well as Zip = Mailing) then I would try the views_field_view module.</p>
  
  <p>I would make one view that pulls together the address details for just Worship, and another one that pulls together just the address for Mailing. Both these need to be set to use Contextual Filter = contact id. And set them both to only show 1 result</p>
  
  <p>Then pull those both in as a Field and obviously use the contact_id as the contextual filter (also needs using on the two views you have to create)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-19T15:56:17.743Z
Answers.Text: Thanks petednz. The individual view per address type worked. I am still not sure what the underlying problem was, but your suggestion helped me to go forward.
Answers.UserDisplayName: Brylie Christopher Oxley
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-29T21:14:47.993Z
Answers.Text: I am trying this solution out, but loading a view within a view can't be great for performance? It would be great to update the views integration code to work with address revisions?
Answers.UserDisplayName: Zachary
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-29T21:21:45.267Z
Answers.Text: Agreed but you can use caches to reduce impact perhaps. And how many folk are likely to be hitting this concurrently? My colleague is also recommending always using the view Relationships to get the Address data rather than the in-built civi field.
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-07T20:19:02.870Z
Answers.LastActivityDate: 2017-06-07T20:19:02.870Z
Answers.UserDisplayName: petednz - fuzion
Body: <p>I have a Drupal view set up to display the CiviCRM address(es) related to a given contact:</p>
  
  <h2>Full view settings</h2>
  
  <p><a href="https://i.sstatic.net/o3oTW.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/o3oTW.png" alt="Drupal view full settings"></a></p>
  
  <h2>Query options</h2>
  
  <p>As a note, I have enabled the <em>Distinct</em> and <em>Pure Distinct</em> settings on the Drupal query settings:</p>
  
  <p><a href="https://i.sstatic.net/oZRF8.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/oZRF8.png" alt="Drupal view query settings showing Distinct and Pure Distinct enabled"></a></p>
  
  <h2>CiviCRM contact page</h2>
  
  <p>On the CiviCRM contact page, there are only, for example, two unique addresses:
  <a href="https://i.sstatic.net/9VpEc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9VpEc.png" alt="CiviCRM Contact page showing two unique addresses"></a></p>
  
  <h2>Duplicate addresses on Drupal view (caching?)</h2>
  
  <p>For some reason, the addresses are appearing multiple times on the Drupal view:</p>
  
  <p><a href="https://i.sstatic.net/mGIvx.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mGIvx.png" alt="Drupal CiviCRM contact view showing duplicate addresses"></a></p>
  
  <p>How can I ensure that only distinct addresses are shown for a given contact?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-03T17:45:36.307Z
Comments.Text: Do you have any Views Relationships set? Can you post a screenshot of the full View, or provide the export code?
Comments.UserDisplayName: jackrabbithanna
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-06T09:10:15.463Z
Comments.Text: Upon closer inspection, I realized all of the addresses are unique. For some reason, the zip code has been changed over time, or other minor changes have been made. How can I show only the latest revision?
Comments.UserDisplayName: Brylie Christopher Oxley
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-06T15:23:10.193Z
Comments.Text: I don't believe there are address revisions, something else happening here. Pls post screenshot of complete View or the View export code so I can dig deep.
Comments.UserDisplayName: jackrabbithanna
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-07T17:55:30.670Z
Comments.Text: I have added a full screenshot to the original question. Might this be some kind of Drupal caching issue?
Comments.UserDisplayName: Brylie Christopher Oxley
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-07T20:37:51.480Z
Comments.Text: If you will notice. The only differences between the two versions of the Mailing and Worship addresses are that the street abbreviation "st" has an added period "st.". I thought there might be a revision stored somewhere, as the repeated addresses seem to be related to changes to the Address records. This is similarly evident on the Drupal view display, where the Albuquerwue addresses have had several minor changes including to the zipcode.
Comments.UserDisplayName: Brylie Christopher Oxley
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-14T03:41:29.043Z
Comments.Text: There appears to be a bug introduced in a recent version of CiviCRM or Drupal. A view set up like this was working correctly as expected for a few years, today I discovered it now displays like this. It seems almost like it displays every possible combination of different address elements from all the addresses. So if you have two address types, one has a postcode and the other doesn't, you will see four addresses, two versions of each type with and without the postcode. If the postcode and the street address are different between the two addresses, you'll see eight different addresses, and so
Comments.UserDisplayName: mjcarter
Tags: <drupal><drupal-views>
Title: How to display only unique CiviCRM Contact Address in Drupal view?
ThreadText: # How to display only unique CiviCRM Contact Address in Drupal view?
  
  (Asked by: username_0 on 2017-06-03)
  
  I have a Drupal view set up to display the CiviCRM address(es) related to a given contact:
  
  ## Full view settings
  
  [![Drupal view full settings](https://i.sstatic.net/o3oTW.png)](https://i.sstatic.net/o3oTW.png)
  
  ## Query options
  
  As a note, I have enabled the *Distinct* and *Pure Distinct* settings on the Drupal query settings:
  
  [![Drupal view query settings showing Distinct and Pure Distinct enabled](https://i.sstatic.net/oZRF8.png)](https://i.sstatic.net/oZRF8.png)
  
  ## CiviCRM contact page
  
  On the CiviCRM contact page, there are only, for example, two unique addresses:
  [![CiviCRM Contact page showing two unique addresses](https://i.sstatic.net/9VpEc.png)](https://i.sstatic.net/9VpEc.png)
  
  ## Duplicate addresses on Drupal view (caching?)
  
  For some reason, the addresses are appearing multiple times on the Drupal view:
  
  [![Drupal CiviCRM contact view showing duplicate addresses](https://i.sstatic.net/mGIvx.png)](https://i.sstatic.net/mGIvx.png)
  
  How can I ensure that only distinct addresses are shown for a given contact?
  
  **Tags:** drupal, drupal-views
  
  > **Comments:**
  > **username_1**: Do you have any Views Relationships set? Can you post a screenshot of the full View, or provide the export code?  
  > **username_0**: Upon closer inspection, I realized all of the addresses are unique. For some reason, the zip code has been changed over time, or other minor changes have been made. How can I show only the latest revision?  
  > **username_1**: I don't believe there are address revisions, something else happening here. Pls post screenshot of complete View or the View export code so I can dig deep.  
  > **username_0**: I have added a full screenshot to the original question. Might this be some kind of Drupal caching issue?  
  > **username_0**: If you will notice. The only differences between the two versions of the Mailing and Worship addresses are that the street abbreviation "st" has an added period "st.". I thought there might be a revision stored somewhere, as the repeated addresses seem to be related to changes to the Address records. This is similarly evident on the Drupal view display, where the Albuquerwue addresses have had several minor changes including to the zipcode.  
  > **username_2**: There appears to be a bug introduced in a recent version of CiviCRM or Drupal. A view set up like this was working correctly as expected for a few years, today I discovered it now displays like this. It seems almost like it displays every possible combination of different address elements from all the addresses. So if you have two address types, one has a postcode and the other doesn't, you will see four addresses, two versions of each type with and without the postcode. If the postcode and the street address are different between the two addresses, you'll see eight different addresses, and so  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_7 on 2017-06-07. Score: 3 | Accepted answer
  
  If you can't sort the above out by ensuring you specify Location type (ie have a field for Zip = Worship, as well as Zip = Mailing) then I would try the views\_field\_view module.
  
  I would make one view that pulls together the address details for just Worship, and another one that pulls together just the address for Mailing. Both these need to be set to use Contextual Filter = contact id. And set them both to only show 1 result
  
  Then pull those both in as a Field and obviously use the contact\_id as the contextual filter (also needs using on the two views you have to create)
  
  > **Comments:**
  > **username_0**: Thanks username_7. The individual view per address type worked. I am still not sure what the underlying problem was, but your suggestion helped me to go forward.  
  > **username_5**: I am trying this solution out, but loading a view within a view can't be great for performance? It would be great to update the views integration code to work with address revisions?  
  > **username_7**: Agreed but you can use caches to reduce impact perhaps. And how many folk are likely to be hitting this concurrently? My colleague is also recommending always using the view Relationships to get the Address data rather than the in-built civi field.  
  
  ---
  
  ### Answer by username_3 on 2017-06-03. Score: 0
  
  Make sure you select only the address where is\_primary = 1
  
  > **Comments:**
  > **username_4**: OR filter by location type = home, billing, work etc .  
  > **username_0**: This seems related to address revisions. The addresses may have been updated over time, for example changing the zip code, and for some reason the view is showing all of the revisions. How can I configure it to show only the current revision?  
  > **username_0**: For what it's worth, we do want to display multiple address *types* on the view, but only the latest revision of each type.  
  > **username_5**: Has anyone figured out how to only show the most recent address revision?  
  
  ---
  
  ### Answer by username_6 on 2020-04-23. Score: 0
  
  If you are still having trouble after setting DISTINCT as an option in the View, and specifying the Location Type hasn't helped -- then a RANDOM sort order may be the issue. Because of the way Drupal views handles random as a column as well as a ORDER BY clause, it breaks the distinctness of the query.
  
  
  ---
  
  