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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update table based on other query 1

Status
Not open for further replies.

mwolf00

Programmer
Nov 5, 2001
4,177
US
Sorry if this seems basic but I'm having a brain cramp this morning. I want to update a table with data from another table but I really don't need to join the two. My query from the second table returns just one row. So it looks something like this
Code:
UPDATE myTable SET
    col1 = subquery.colA
    , col2 = subquery.colB
WHERE myTable.col3 = 'some value'

[blue]subquery[/blue]
SELECT colA, colB 
FROM anotherTable 
WHERE colC = 'some other value'

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 

Try this:
Code:
UPDATE myTable 
   SET (col1, col2) = (
       SELECT colA, colB 
         FROM anotherTable 
        WHERE colC = 'some other value')
WHERE myTable.col3 = 'some value';
[3eyes]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thank you!

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top