title: whats purpose of nested query if the result could be obtained by inner query itself
body: <p>I am beginner level in sql queries. I would like to know the purpose of outer query if the result could be obtained from inner query itself. Like in below case we are deleting set of records from a table which are less than particular timestamp(other matching conditions are matching unique keys but I wonder why we need to check equality for unique keys in same table). This query is written for purge process, we are deleting records from a table which are older than particular timestamp and for extra information we execute this query from java. But my question is to understand the purpose of outer query, if we can achieve result from inner query itself.</p>
  <p>Nested query we have:</p>
  <pre><code>DELETE FROM ORDER_LOG T1 
   WHERE EXISTS (select * 
                   FROM (SELECT VENDOR_NBR, ITEM_NBR, ORDER_ID, PDT_CODE, LOG_TS
                           FROM ORDER_LOG WHERE  LOG_TS &lt; &quot;timestamp&quot; 
                          FETCH FIRST 100000 ROWS ONLY) AS T2 
                  WHERE (T1.LOG_TS = T2.LOG_TS 
                    AND T1.VENDOR_NBR= T2.VENDOR_NBR 
                    AND T1.ORDER_ID=T2.ORDER_ID))
  </code></pre>
  <p>Non nested query(that I think of executable and produce same result):</p>
  <pre><code>DELETE FROM ORDER_LOG 
   WHERE  LOG_TS&lt; &quot;timestamp&quot; 
   FETCH FIRST 100000 ROWS ONLY
  </code></pre>