Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update 2

Status
Not open for further replies.

CIMTEET

Programmer
Jun 25, 2001
182
US
Can multiple fields be updated at the same time without using a FOR UPDATE?
 

Yes:
Code:
UPDATE MyTable
    SET Col1 = Val1, Col2 = Val2;
-- or --
UPDATE MyTable
   SET (Col1, Col2) = (
       Select Fld1, Fld2 From OtherTable
         Where {condition};

[3eyes]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
What if I want to make it a many to one relationship. Multiple fields to the same value?
 
Do you mean multiple fields in the same table? If so, you certainly may do so. Using LK's earlier code:
Code:
UPDATE MyTable
    SET Col1 = <same value>
       ,Col2 = <same value>
       ...;
-- or --
UPDATE MyTable
   SET (Col1, Col2,...) = (
       Select <same value>, <same value>,... From OtherTable
         Where {condition};
Is this what you meant?

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
 
No. I already have the data from a previous query. I wanted to place one value in both of the table columns like this:

UPDATE MyTable
SET (Col1, Col2,...) = (n_system_track_id) where blah blah;

I tried it but it said that it had to be a subquery. I probably ought to type the code in here. I am developing on a unix machine and all data extraction routes are purposely blocked if you understand my drift.
 

Like this?
Code:
UPDATE MyTable
   SET Col1 = n_system_track_id
     , Col2 = n_system_track_id
 WHERE blah blah;
[ponder]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
UPDATE MyTable
SET (Col1, Col2,...) = (SELECT n_system_track_id , n_system_track_id FROM ( Your Query) );

 
LKB,
Yeah, I wasn't sure about the syntax, thats exactly what I need if that works. The n_system_track_id was data retreived from a previous query. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top