title: How to delete multiple rows from multiple tables using Where clause?
body: <p>Using an Oracle DB, I need to select all the IDs from a table where a condition exists, then delete the rows from multiple tables where that ID exists. The pseudocode would be something like:</p>
  
  <pre><code>SELECT ID FROM TABLE1 WHERE AGE &gt; ?
  DELETE FROM TABLE1 WHERE ID = &lt;all IDs received from SELECT&gt;
  DELETE FROM TABLE2 WHERE ID = &lt;all IDs received from SELECT&gt;
  DELETE FROM TABLE3 WHERE ID = &lt;all IDs received from SELECT&gt;
  </code></pre>
  
  <p>What is the best and most efficient way to do this?</p>
  
  <p>I was thinking something like the following, but wanted to know if there was a better way.</p>
  
  <pre><code>PreparedStatement selectStmt = conn.prepareStatment("SELECT ID FROM TABLE1 WHERE AGE &gt; ?");
  selectStmt.setInt(1, age);
  ResultSet rs = selectStmt.executeQuery():
  
  PreparedStatement delStmt1 = conn.prepareStatment("DELETE FROM TABLE1 WHERE ID = ?");
  PreparedStatement delStmt2 = conn.prepareStatment("DELETE FROM TABLE2 WHERE ID = ?");
  PreparedStatement delStmt3 = conn.prepareStatment("DELETE FROM TABLE3 WHERE ID = ?");
  
  while(rs.next())
  {
      String id = rs.getString("ID");
  
      delStmt1.setString(1, id);
      delStmt1.addBatch();
  
      delStmt2.setString(1, id);
      delStmt2.addBatch();
  
      delStmt3.setString(1, id);
      delStmt3.addBatch();
  }
  
  delStmt1.executeBatch();
  delStmt2.executeBatch();
  delStmt3.executeBatch();
  </code></pre>
  
  <p>Is there a better/more efficient way?</p>