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

Updating multiple rows

Status
Not open for further replies.

adrian0605

Programmer
Apr 3, 2007
10
0
0
RO

I've got a problem in updating a rows.
I've tryed to update a value from the field "QQQ" which correspond with the field "PPP" from a table.
Problem seems to be when I have more than one "PPP" in a different table, because I use a subquery which returns more than one "PPP" that's because in that table could be more that one "PPP". If is one, I don't have a problem, query's working well.

Can somebody tell me if is any way to do it in SQL?
Thanx in advance.
 
So are you trying to update some other column where PPP = QQQ? If so, maybe something like this? Assumes that all of your different 'PPP' are alike. Dont run this unless you've got a backup

Code:
[COLOR=blue]update[/color] a
[COLOR=blue]set[/color] a.SomeColumn = b.SomeColumn
[COLOR=blue]from[/color] leTable a
[COLOR=blue]inner[/color] [COLOR=blue]join[/color]
(
[COLOR=blue]select[/color] [COLOR=#FF00FF]distinct[/color] MatchingColumn, PPP 
[COLOR=blue]from[/color] zeOtherTable
) b
[COLOR=blue]on[/color] a.QQQ = b.PPP

Hope it helps,

Alex



Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top