title: SQL query to select only not even rows
body: <p>I have an order table holding columns : </p>
  
  <pre><code>ID
  date
  order_number
  cost
  </code></pre>
  
  <p>In the table there are the following rows : </p>
  
  <pre><code>1,TODAY,123,100
  2,YESTERDAY, 123,150
  3,TODAY, 144,20
  4,TODAY, 144,20
  5,TODAY, 144,200
  </code></pre>
  
  <p>(Notice that the 3rd column is the order number)</p>
  
  <p>In the result set returned there should return :</p>
  
  <pre><code>1,TODAY,123,100
  3,TODAY, 144,20
  4,TODAY, 144,20
  </code></pre>
  
  <p>I am a poor SQL know-how (A web designer, go figure).</p>
  
  <hr>
  
  <h2>Fixed and found the answer</h2>
  
  <p>After searching and researching i found what i needed.
  I put all the records in a temporary table and run a cursor holding the order_number and the count of rows for the order_number like this : </p>
  
  <blockquote>
    <p>declare cur cursor for<br>
         SELECT order_number,((COUNT(*) + 1) / 2) as
          counter from @tmpTbl group by order_number</p>
  </blockquote>
  
  <p>Now i run over the cursor and insert into another table the top(counter) from the @tmpTbl into another table with the same structure (lets call it @slimTbl).
  So, we have this piece of code :</p>
  
  <pre><code>&gt;fetch next from cur into @order_number,@counter
  &gt;
  &gt;while @@FETCH_STATUS = 0
  &gt;
  &gt;   begin
  &gt;
  &gt;     INSERT INTO @slimTbl (id,date,order_number,cost)
  &gt;
  &gt;            (SELECT TOP(@counter) id,date,order_number,cost FROM @tmpTbl
  &gt;             WHERE order_number = @order_number )
  &gt;
  &gt;     fetch next from cur into @order_number,@counter
  &gt;
  &gt;   end
  &gt;
  &gt;close cur 
  &gt;
  &gt;deallocate cur 
  </code></pre>
  
  <p>I hope this is clear now. I thank you all for helping me...
  Feel free to contact me to see the full solution I created.. a little long but works like magic :)</p>