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

Home -> Community -> Usenet -> c.d.o.tools -> update based on join

update based on join

From: James Pugh <james_pugh_at_mindspring.com>
Date: Sun, 1 Oct 2000 08:53:58 -0700
Message-ID: <8r7mpt$h6i$1@slb7.atl.mindspring.net>

Forgive my sexist example. I'm working on a Sunday, so I made an example that amuses me.

I want to update certain rows in a table based on a join to another table.

Here's the example and the SQL is used. Is there a better way to do the same thing?

SQL> describe boys

 Name                                      Null?    Type

----------------------------------------- -------- --------------
NAME CHAR(30) LENGTH FLOAT(126) SQL> describe girls Name Null? Type
----------------------------------------- -------- --------------
NAME CHAR(30) FRIEND CHAR(30) BRA CHAR(3)

SQL> select * from boys;

NAME                               LENGTH
------------------------------ ----------
James                                   9
Ron                                    10
Todd                                   10
Jeremy                                 10

SQL> select * from girls;

NAME                           FRIEND                         BRA
------------------------------ ------------------------------ ---
Karen                          James                          C
Trish                          Todd                           A
Val                            Todd                           A
Tiffany                        James                          C
Misty                          James                          C

SQL>
update girls z set bra = 'C' where (select a.name from boys a, girls b where b.name = z.name and a.name = b.friend)='James';

The update changes the bra size for all girls with 'James' as a friend. Received on Sun Oct 01 2000 - 10:53:58 CDT

Original text of this message

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