How to delete rows based on field value but not if certain other field values Dont exist
<p>I am working on a financial reporting table for my business and trying to "massage" the data into something the parent company wants to read. I am VERY close.</p>

<p>Essentially, I have this: </p>

<pre><code>Account FPeriod    Balance
   1          0      42
   1          1      53
   1          2      11
   2          0      62
   3          0     567
   3          1     564
   3          2      34
</code></pre>

<p>where each account has multiple rows, one for each fiscal period it has transactions in.
Fiscal period 0 represents the opening balance of the account for the fiscal year.</p>

<p>What I need to do is delete rows with fiscal period 0 but not if it is the only entry for that account.</p>

<p>I have done:</p>

<pre><code>Delete from TABLE  
WHERE Fperiod = 0
</code></pre>

<p>but this removes all the rows with FPeriod 0 where for instance i need to keep account 2 FPeriod 0 as it's the only entry for that account. I do need to delete account 1 and 3 FPeriod 0 rows.</p>

<p>I am not even sure where to begin, thinking maybe a while loop? I hear those are bad if you can avoid them.</p>

<p>I need the output to look like this:</p>

<pre><code>Account FPeriod    Balance
       1          1      53
       1          2      11
       2          0      62
       3          1     564
       3          2      34
</code></pre>

<p>Any ideas?</p>