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!

Update problem 1

Status
Not open for further replies.

jfokas

Programmer
Apr 28, 2002
42
0
0
I am trying to update some rows of a table with information in the same column from different rows. The statement I'm trying to use is:

update delivery_location_2
set courier_route = dl2.courier_route
from delivery_location_2 dl1, delivery_location_2 dl2
where dl1.group_id = dl2.id and dl1.entity_type = 'R'
and dl1.group_id is not null

this syntax has always worked for me in the past when I'm dealing with two different tables. But in working from the same table, I get a "ambiguous table name" error. I've tried a variety of variations to no avail. What is that obvious syntax that I'm overlooking?

Thanks,

John

 
Create a view of the table and do a join on the original table and the view. The ambiguity is gone!
-Karl
 
Thanks to someone elses post I discovered the "right" way to do what you want.

update dl1
set courier_route = dl2.courier_route
from delivery_location_2 dl1, delivery_location_2 dl2
where dl1.group_id = dl2.id and dl1.entity_type = 'R'
and dl1.group_id is not null

-Karl
 
Thanks Karl,

It worked like a charm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top