home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.databases:8460 comp.databases.oracle:2495
- Path: sparky!uunet!usc!wupost!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!jvnc.net!netnews.upenn.edu!msuinfo!oak!newton!strobel
- From: strobel@newton.mcs.gvsu.edu (Stephen Strobel)
- Newsgroups: comp.databases,comp.databases.oracle
- Subject: Re: Weird ORACLE update statement
- Message-ID: <1992Dec12.143257.8808@mcs.gvsu.edu>
- Date: 12 Dec 92 14:32:57 GMT
- References: <1992Dec8.153620.9115@infonode.ingr.com> <1992Dec8.210428.22025@cbnewsk.cb.att.com>
- Sender: news@mcs.gvsu.edu
- Distribution: na
- Organization: Grand Valley State University, Allendale MI
- Lines: 47
- Nntp-Posting-Host: newton
-
- In article <1992Dec8.210428.22025@cbnewsk.cb.att.com> jrmo@prpix2.att.com (J.R.Moore) writes:
- >In article <1992Dec8.153620.9115@infonode.ingr.com> mcintyre@infonode.ingr.com (John Scott Mcintyre) writes:
- >> I am using ORACLE and want to be able to update rows in table1 using
- >> columns from table2 when the two tables can be joined.
- >>
- >> The SQL statement I would like to perform would look like this:
- >>
- >> update table1 set table1.manufacturer=table2.manufact,
- >> set table1.pur_cost=table2.sale_cost
- >> where table1.inv_number=table2.inv_number;
- >>
- >> The problem is UPDATE apparently cannot handle multiple tables.
- >>
- >Try this:
- >
- >UPDATE table1 A
- >SET manufacturer=(
- > SELECT table2.manufact
- > FROM table2
- > WHERE A.inv_number=table2.inv_number
- > ),
- > pur_cost=(
- > SELECT table2.sale_cost
- > FROM table2
- > WHERE A.inv_number=table2.inv_number
- > )
- >WHERE inv_number IN (
- > SELECT table2.inv_number
- > FROM table1,table2
- > WHERE table1.inv_number=table2.inv_number
- > )
- >;
- >
- >Joe Moore
-
- Better yet:
-
- Update Table1 A
- Set (manufacturer, pur_cost) =
- (Select manufacturer, sale_cost
- from table2 B
- where A.inv_number = B.inv_number)
- --
- |--------------------------------------|--------------------------------------|
- | Stephen Strobel | Phone: (h) (616) 235-1263 |
- | Grand Valley State University | (w) (616) 940-4241 | | | Mail: strobel@newton.mcs.gvsu.edu |
- |--------------------------------------|--------------------------------------|
-