title: Update ONE record per condition in a table
body: <p>I looked into this thread, and I thought I'd find my answers there, but unfortunately didn't ...</p>
  
  <p><a href="https://stackoverflow.com/questions/244671/update-statement-in-oracle-using-sql-or-pl-sql-to-update-first-duplicate-row-onl">UPDATE statement in Oracle using SQL or PL/SQL to update first duplicate row ONLY</a></p>
  
  <p>If our customers don't have a default email address selected I need to update that value.</p>
  
  <p>The following statement updates ALL records of that table if the customer does not have a default email yet:</p>
  
  <pre><code>update si_contactemails 
  set ISDEFAULT = 'Y'
  where entityid in
  (select customerid from si_customers where custstatus = 'A' and deleted = 0)
  and entityid in (select entityid from si_contactemails group by entityid having MAX(ISDEFAULT) = 'N')
  </code></pre>
  
  <p>But if a customer happens to have more than one entry in the si_contactemails table I only need the first record for this customer updated, can only have one default.</p>
  
  <p>I tried with the following addition which I found in the article mentioned above, but it only updates the first record for which all conditions are true - how can I update all records for which the conditions are true?</p>
  
  <pre><code>update si_contactemails 
  set ISDEFAULT = 'Y'
  where entityid in
  (select customerid from si_customers where custstatus = 'A' and deleted = 0)
  and entityid in (select entityid from si_contactemails group by entityid having MAX(ISDEFAULT) = 'N')
  AND rowid = (SELECT min(rowid) 
                   FROM   si_contactemails 
                   WHERE entityid in (select min(entityid) from si_contactemails group by entityid having MAX(ISDEFAULT) = 'N'))
  </code></pre>
  
  <p>Any input appreciated :-)</p>
  
  <p>Thanks a lot, </p>
  
  <p>Steph</p>