Home » SQL & PL/SQL » SQL & PL/SQL » query rewrite
query rewrite [message #643058] Sun, 27 September 2015 18:22 Go to next message
gidiyap
Messages: 2
Registered: September 2015
Junior Member
i have a query below but i'm having difficulties in rewriting it. any other approach you have in mind?

delete from
table1 a, table2 b
where
a.col1 =b.col1
a.col2 = b.col2
a.col3 < b.col3


if the last filter condition does not exist
a.col3 < b.col3
, i can easily use the approach below, however, that last filter is a roadblock to me..

delete from
table1
where (col1, col2, col3) in ( select b.col1, b.col2, b.col3 from table2 b)
Re: query rewrite [message #643059 is a reply to message #643058] Sun, 27 September 2015 18:59 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum.


Please read and follow the forum guidelines, to enable us to help you:
OraFAQ Forum Guide
How to use {code} tags and make your code easier to read

We don't know what constitutes correct/desired results.
Re: query rewrite [message #643060 is a reply to message #643059] Sun, 27 September 2015 19:08 Go to previous messageGo to next message
gidiyap
Messages: 2
Registered: September 2015
Junior Member
Hi blackswan. Thanks for checking my post. My desired result is that to optimize the query itself. i just basically would like to know if there are any other way to reconstruct the delete statement on a query level only. i'm pretty much new in query reconstruction.
Re: query rewrite [message #643061 is a reply to message #643060] Sun, 27 September 2015 19:15 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Realize that we don't have your tables & we don't have your data.
Therefore we can't run posted DELETE statement.

use COPY & PASTE to show us the results when you execute DELETE statement.

post EXPLAIN PLAN for the SQL
Re: query rewrite [message #643068 is a reply to message #643058] Mon, 28 September 2015 04:59 Go to previous message
sandeep_orafaq
Messages: 88
Registered: September 2014
Member
May be you can try exists clause.

Something like
delete from table1
 where exists (select null
          from table2
         where table1.col1 = table2.col1
           and table1.col2 = table2.col2
           and table1.col3 < table2.col3);
Previous Topic: NVL vs IS NULL
Next Topic: No numbers on Imbalance and Variance...
Goto Forum:
  


Current Time: Fri Apr 19 15:18:06 CDT 2024