Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> What is the difference between this two SQL?

What is the difference between this two SQL?

From: <emdproduction_at_hotmail.com>
Date: Wed, 5 Dec 2007 07:33:18 -0800 (PST)
Message-ID: <b281c75b-c504-4ccd-b409-00b91aa1c51c@f3g2000hsg.googlegroups.com>


Group,

I would like to update table test from test1. But I do not understand why we need to use where exists subquery

SQL> select * from test;

        ID COL1
---------- ----------

         1 a1
         2 b1
         3 c1
         4 d1

SQL> select * from test2;

        ID COL1
---------- ----------

         1 a2
         2 b2
         3 c2
         4

Both two update statement seems to be working; SQL> update test
  2 set col1 = (select col1 from test2
  3 where test.id=test2.id);

4 rows updated.

SQL> select * from test;

        ID COL1
---------- ----------

         1 a2
         2 b2
         3 c2
         4

SQL> rollback;

Rollback complete.

SQL> select * from test;

        ID COL1
---------- ----------

         1 a1
         2 b1
         3 c1
         4 d1

SQL> update test
  2 set col1 = (select col1 from test2
  3 where test.id=test2.id)
  4 where exists
  5 (select 1 from test2 where test.id=test2.id);

4 rows updated.

SQL> select * from test;

        ID COL1
---------- ----------

         1 a2
         2 b2
         3 c2
         4

Is it necessary to use the exists where clause?

Thanks for your help. Received on Wed Dec 05 2007 - 09:33:18 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US