Answers.Body: <p>If I understand your question and structure correctly, then this might work.</p>
  
  <pre><code>{% entries = craft.entries.section('series').limit(null) %}
  {% mostRecentSermons = [] %}
  
  {% for entry in entries %}
  
      {# retrieve most recent sermon related to series #}
      {% set sermon = craft.entries.section('sermons').relatedTo(entry).order('postDate desc').first %}
  
      {# merge sermon into mostRecentSermons array #}
      {% set mostRecentSermons = mostRecentSermons|merge([sermon]) %}
  
  {% endfor %}
  </code></pre>
  
  <p>If you need to worry about duplicates then you can use <code>{% if not sermon in mostRecentSermons %}</code> before merging.</p>
  
  <p>You may also want to wrap this in <code>{% cache %}{% endcache %}</code> tags to improve performance.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-28T22:39:27.407Z
Answers.Text: Perfect, thank you!
Answers.UserDisplayName: Ryan James
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-09T03:46:25.370Z
Answers.LastActivityDate: 2015-02-09T03:46:25.370Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>Here is my situation: I have a bunch of different series (which are each stored in a channel), and there are a bunch of sermons related to each series.</p>
  
  <p>What I need to do is display the most recent entry of each series. Typically I would do this in a SELECT DISTINCT SQL query; How should I go about doing it in Craft?</p>
  
Tags: <entries><relations>
Title: Select distinct entries?
ThreadText: # Select distinct entries?
  
  (Asked by: username_0 on 2015-02-09)
  
  Here is my situation: I have a bunch of different series (which are each stored in a channel), and there are a bunch of sermons related to each series.
  
  What I need to do is display the most recent entry of each series. Typically I would do this in a SELECT DISTINCT SQL query; How should I go about doing it in Craft?
  
  **Tags:** entries, relations
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-02-09. Score: 2
  
  If I understand your question and structure correctly, then this might work.
  
  ```
  {% entries = craft.entries.section('series').limit(null) %}
  {% mostRecentSermons = [] %}
  
  {% for entry in entries %}
  
      {# retrieve most recent sermon related to series #}
      {% set sermon = craft.entries.section('sermons').relatedTo(entry).order('postDate desc').first %}
  
      {# merge sermon into mostRecentSermons array #}
      {% set mostRecentSermons = mostRecentSermons|merge([sermon]) %}
  
  {% endfor %}
  
  ```
  
  If you need to worry about duplicates then you can use `{% if not sermon in mostRecentSermons %}` before merging.
  
  You may also want to wrap this in `{% cache %}{% endcache %}` tags to improve performance.
  
  > **Comments:**
  > **username_0**: Perfect, thank you!  
  
  ---
  
  