Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You <em>can</em> change this to a <code>where exists</code>, but you probably want to <code>join</code> instead:</p> <pre><code>SELECT B.eid FROM JBB B JOIN ( SELECT eid, estat, acct_type, acct_id , max(acct_id) over ( partition by eid ) as max_acct FROM pbank ) A ON b.eid = a.eid JOIN pbranch C ON a.bankid = c.bankid AND a.branchid = c.brahchid WHERE c.sourceid = :1 AND c.estat = :2 AND a.ESTAT = :3 AND a.acct_type = :4 AND a.acct_id = a.max_acct </code></pre> <p>By using the analytic function <code>max()</code> you remove the need for a sub-select; it's also a lot clearer, I think, to do things in this manner.</p> <hr> <p>And, your newly added query becomes:</p> <pre><code>SELECT A1.clrn_id, A1.gpgroup, A1.cl_id FROM p_dtl A1 JOIN gp_cl_rn run ON A1.clrn_id = run.clrn_id WHERE A1.PYMT_DT = TO_DATE(:1 ,'YYYY-MM-DD') AND run.clrn_id = a1.clrn_id AND run.finalized_ind = :2 </code></pre> <p>I notice that you're explicitly using the <code>to_date()</code> function, which implies that you're storing a date as a string. This is bad practice and likely to cause you trouble in the longer run... avoid it if at all possible.</p> <hr> <pre><code>max(acct_id) over ( partition by eid ) </code></pre> <p>is an <a href="http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions004.htm#SQLRF06174" rel="nofollow">analytic function</a>; this does exactly the same as the aggregate function <code>max()</code>, except instead of requiring a GROUP BY, it returns the same result for <em>every</em> row in the result set.</p> <p>This particular use returns the maximum <code>acct_id</code> for every <code>eid</code>. There's a whole host of analytic functions, but the best thing to do is to try it for yourself. There are also <a href="http://www.orafaq.com/node/55" rel="nofollow">several examples</a> available online.</p> <p>Using a JOIN is not <em>necessarily</em> quicker than a <code>where exists</code>, it just depends what you're after. As with everything I would recommend trying both and seeing what suits your particular situation more.</p> <p>Generally, they have different purposes; <code>where exists</code> is designed to stop "calculating" rows when a single row that fulfils the conditions is found. JOIN, does everything. In your case as you want everything there <em>may</em> be little to chose between them but I would always use JOIN; just ensure that your indexes are correct.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload