title: SQL query with priority on OR condition
body: <p>I have a sample table like this</p>
  
  <pre><code>+----+-------+--------+---------+
  | Id | Type  | Format | Default |
  +----+-------+--------+---------+
  |  1 | IMAGE | PNG    | true    |
  |  2 | IMAGE | PNG    | false   |
  |  3 | IMAGE | JPG    | false   |
  |  4 | IMAGE | JPG    | true    |
  |  5 | VIDEO | MP4    | false   |
  +----+-------+--------+---------+
  </code></pre>
  
  <p>And I need to implement a query like this</p>
  
  <pre><code>SELECT * FROM media WHERE type = 'IMAGE' and format = 'PNG'
  </code></pre>
  
  <p>If the query gives 0 results, the <code>format</code> filter need to be replaced with</p>
  
  <pre><code>SELECT * FROM media WHERE type = 'IMAGE' and default = TRUE
  </code></pre>
  
  <p>So, there is a fixed filter which is always there (on both attempts), for this example is made using <code>type = 'IMAGE'</code> and 2 filters that need to combined basing on the results size of the first condition</p>
  
  <p>I'm trying to understand if there is a way to do a single query which can join both conditions, some sort of priority on the first condition <code>format</code> which will exclude the results from the second condition <code>default</code></p>
  
  <p>Something like this</p>
  
  <pre><code>SELECT * FROM media WHERE type = 'IMAGE' AND (format = 'PNG' OR default = TRUE)
  </code></pre>
  
  <p>is not suitable because no matter if the first condition give at least 1 result, the <code>OR</code> condition will always give the <code>default=TRUE</code> records.</p>
  
  <p>I thought about the <code>XOR</code> operator, but it will exclude all the PNG results which are NOT default. Instead for the <code>format</code> filter the value of <code>default</code> is to be ignored</p>
  
  <p>Is there a way to reproduce this behaviour using only 1 query?</p>
  
  <p>The expected result</p>
  
  <p>Example 1) It exists at least a PNG, so those are gathered (default or non default does not matter, the <code>format</code> filter have priority on that)</p>
  
  <pre><code>conditions = [format = 'PNG' | default = true]
  |  1 | IMAGE | PNG    | true    |
  |  2 | IMAGE | PNG    | false   |
  </code></pre>
  
  <p>Example 2) It exists at least a JPG, so those are gathered</p>
  
  <pre><code>conditions = [format = 'JPG' | default = true]
  |  3 | IMAGE | JPG    | false   |
  |  4 | IMAGE | JPG    | true    |
  </code></pre>
  
  <p>Example 3) No GIF exists, so all the default are gathered</p>
  
  <pre><code>conditions = [format = 'GIF' | default = true]
  |  1 | IMAGE | PNG    | true    |
  |  4 | IMAGE | JPG    | true    |
  </code></pre>