title: Eliminating duplicate rows except one column with condition
body: <p>I am having trouble trying to find an appropriate query(SQL-SERVER) for selecting records with condition however, the table I will be using has more than 100,000 rows and more than 20 columns.</p>
  
  <p>So I need a code that satisfies the following condition:</p>
  
  <p>1.)If [policy] and [plan] column is unique between rows then I will select that record</p>
  
  <p>2.)If [policy] and [plan] return 2 or more rows then I will select the record which 'code' column isn't 999</p>
  
  <p>3.)In some cases the unwanted rows may not have '999' in [code] column but may be other specifics</p>
  
  <p>In other words, I would like to get row number 1,2,4,5,7.</p>
  
  <p>Here is an example of what the table looks like</p>
  
  <pre><code>row #|policy|plan|code
  -----------------------
    1  |  a   | aa |111
  -----------------------
    2  |  b   | bb |112
  -----------------------
    3  |  b   | bb |999
  -----------------------
    4  |  c   | cc |111
  -----------------------
    5  |  c   | cc |112
  -----------------------
    6  |  c   | cc |999
  -----------------------
    7  |  d   | dd |999
  -----------------------
  </code></pre>
  
  <p>I'm expecting to see something like</p>
  
  <pre><code>row #|policy|plan|code
  -----------------------
    1  |  a   | aa |111
  -----------------------
    2  |  b   | bb |112
  -----------------------
    4  |  c   | cc |111
  -----------------------
    5  |  c   | cc |112
  -----------------------
    7  |  d   | dd |999
  -----------------------
  </code></pre>
  
  <p>Thank you in advance</p>