Answers.Body: <p>You've got your two obvious choices nailed down.  You're either offloading the filtering to MySQL (running 3 separate queries so that MySQL filters the data) or you're grabbing all of the data and filtering it on the Twig/PHP side.</p>
  
  <p>Which one is more performant likely depends on 1) how much data you're talking about and 2) your environment (resources allocated to MySQL vs. PHP).</p>
  
  <p>For your particular case, I'd enable <a href="https://craftcms.com/docs/config-settings#devMode" rel="nofollow">devMode</a> and analyze the performance metrics between the two methods while taking into account how fast the data might increase in the future and make an educated guess based on that information.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-06T06:35:45.213Z
Answers.Text: And how would I do this in Twig? The first thing think of is looping through all entries and do an if/else in the loop (`{% if playerPosition = "goalie" %}do stuff{% endif %}`). Would that be correct?
Answers.UserDisplayName: Bart Rylant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-06T17:49:53.987Z
Answers.Text: @BartRylant yup, that's what I was thinking!
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-06T04:30:32.483Z
Answers.LastActivityDate: 2016-09-06T04:30:32.483Z
Answers.UserDisplayName: Brad Bell
Body: <p>Is there a kind of “search in results after you retreived all entries” thing? Thing is: I have this query:
  <code>craft.entries.section('players').limit(null)
  </code>
  I want to show all entries where <code>playerPosition</code> = goalie. And on the same page, I want to show all players where <code>playerNationality</code> = Nederlands. And on the same page I want to show the longest player (sorted by <code>playerHeight</code>).</p>
  
  <p>I can off course run a query 3 times:</p>
  
  <pre><code>goalies = craft.entries.section('players').playerPosition('goalie').limit(null)
  nationalplayers = craft.entries.section('players').playerNationality('Nederlands').limit(null)
  longest = craft.entries.section('players').order('playerLength desc').first();
  </code></pre>
  
  <p>That would work, but I'm running a query 3 times on the same section. There must be a better way, right? – Some have told me about the SuperSort plugin (which was indeed the right solution for my <a href="https://craftcms.stackexchange.com/questions/16489/order-by-fields-after-searching">previous question</a>), but that only <em>sorts</em> results. It's not a real filter.</p>
  
Tags: <entries><search><filter>
Title: Filter results after searching
ThreadText: # Filter results after searching
  
  (Asked by: username_0 on 2016-09-05)
  
  Is there a kind of “search in results after you retreived all entries” thing? Thing is: I have this query:
  `craft.entries.section('players').limit(null)`
  I want to show all entries where `playerPosition` = goalie. And on the same page, I want to show all players where `playerNationality` = Nederlands. And on the same page I want to show the longest player (sorted by `playerHeight`).
  
  I can off course run a query 3 times:
  
  ```
  goalies = craft.entries.section('players').playerPosition('goalie').limit(null)
  nationalplayers = craft.entries.section('players').playerNationality('Nederlands').limit(null)
  longest = craft.entries.section('players').order('playerLength desc').first();
  
  ```
  
  That would work, but I'm running a query 3 times on the same section. There must be a better way, right? – Some have told me about the SuperSort plugin (which was indeed the right solution for my [previous question](https://craftcms.stackexchange.com/questions/16489/order-by-fields-after-searching)), but that only *sorts* results. It's not a real filter.
  
  **Tags:** entries, search, filter
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-09-06. Score: 1
  
  You've got your two obvious choices nailed down. You're either offloading the filtering to MySQL (running 3 separate queries so that MySQL filters the data) or you're grabbing all of the data and filtering it on the Twig/PHP side.
  
  Which one is more performant likely depends on 1) how much data you're talking about and 2) your environment (resources allocated to MySQL vs. PHP).
  
  For your particular case, I'd enable [devMode](https://craftcms.com/docs/config-settings#devMode) and analyze the performance metrics between the two methods while taking into account how fast the data might increase in the future and make an educated guess based on that information.
  
  > **Comments:**
  > **username_0**: And how would I do this in Twig? The first thing think of is looping through all entries and do an if/else in the loop (`{% if playerPosition = "goalie" %}do stuff{% endif %}`). Would that be correct?  
  > **username_1**: @username_0 yup, that's what I was thinking!  
  
  ---
  
  