title: Filter out records based on condition SQL
body: <p>I am trying to filter out some records based on condition but couldn't get the proper results.</p>
  <p>Data:</p>
  <pre><code>GID OID SID  Z
  1   1   1    A
  1   2   2    B
  1   3   3    C
  1   2   4    B
  
  </code></pre>
  <p>Expected Result:</p>
  <pre><code>GID OID SID Z
  1   1   1   A
  1   3   3   C
  </code></pre>
  <p>Here GID, OID can be repeated but not SID.</p>
  <p>Need to filter out all records where Z contains 'A' &amp; 'C'</p>
  <p>What I have tried:</p>
  <pre><code>select distinct GID, OID, SID, Z
  from table
  where Z ilike ('A') or Z ilike ('C')
  </code></pre>
  <p>but this query will include all record of sample GID records.
  Moreover I have also thought of self join but could not frame the query around that.</p>