title: SQL query to compare one column with another
body: <p>This is for a small project I'm doing. I am trying to write a query which can do this on the following table</p>
  <blockquote>
  <p>ID, Name, Pledge_Amount , Pledge_payment_amt , Gift_No, Pledge_Gift_No, Pledge_Open/Closed</p>
  </blockquote>
  <p>ID isn't unique. So, one person would have pledged some money (Pledge_Amount), would have paid the full or part of it (Pledge_payment_amt) with multiple records for the same. The Gift_no will be be the same for the same pledge/gift and will match with the Pledge_Gift_No whenever the person decides to donate. Only when the gift has been completely paid off, the status will change.</p>
  <blockquote>
  <p>1, Alex, 20, 10, G1, NULL, Open</p>
  <p>1, Alex, NULL,10, NULL, G1, Closed</p>
  </blockquote>
  <p>And the query is:</p>
  <blockquote>
  <p>Find the persons with outstanding gift amounts and change their status to open/closed</p>
  </blockquote>
  <p>So far, I have been able to do this:</p>
  <pre><code>select *
  from Test_Table2 S inner join Test_Table2 F
  on S.Gift_No = F.Pledge_gift_No
  WHERE S.ID = F.ID;
  </code></pre>
  <p>Any pointers on how to go about with the rest of the query will be greatly appreciated.</p>