Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> update based on join
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
![]() |
![]() |