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

Home -> Community -> Usenet -> comp.databases.oracle -> Re: common UPDATE syntax for SqlServer and Oracle

Re: common UPDATE syntax for SqlServer and Oracle

From: David Portas <REMOVE_BEFORE_REPLYING_dportas_at_acm.org>
Date: Thu, 25 Nov 2004 23:02:53 -0000
Message-ID: <qoednbGWLZwC-TvcRVn-1A@giganews.com>


The ANSI Standard syntax supported by both products is

UPDATE Table1
 SET city_id =
(SELECT T2.id

   FROM Table2 AS T2
   WHERE T2.city = Table1.city) ;

Depending on requirements you may want to include a WHERE EXISTS (equivalent to the proprietary INNER JOIN syntax)

UPDATE Table1
 SET city_id =
(SELECT T2.id

   FROM Table2 AS T2
   WHERE T2.city = Table1.city)
 WHERE EXISTS
(SELECT *

   FROM Table2 AS T2
   WHERE T2.city = Table1.city) ;

-- 
David Portas
SQL Server MVP
--
Received on Thu Nov 25 2004 - 17:02:53 CST

Original text of this message

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