Oracle Update one table from another table with join

I have an Oracle Table for Project
    Project_Id  Project name  ProjManger   User_ID
(User ID column is blank now.All other fields are filled)

I have user table
   User_Id   UserName

I need a query to update the User_ID in project table with User_ID in User table where Project.ProjManager = User.Username
Sam OZAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulEE Topic AdvisorCommented:
CREATE TABLE Projects
    (Project_Id int, ProjectName varchar2(8), ProjManger varchar2(4), User_ID int)
;

INSERT ALL 
    INTO Projects (Project_Id, ProjectName, ProjManger, User_ID)
         VALUES (1, 'ProjectX', 'Paul', NULL)
SELECT * FROM dual
;

CREATE TABLE Users
    (ID int, NAME varchar2(4))
;

INSERT ALL 
    INTO Users (ID, NAME)
         VALUES (201, 'Paul')
SELECT * FROM dual
;

Open in new window

update projects p
set p.User_ID = (select u.id from users u where p.ProjManger = u.name)
where p.User_ID IS NULL
;

select p.*from projects p;

| PROJECT_ID | PROJECTNAME | PROJMANGER | USER_ID |
|------------|-------------|------------|---------|
|          1 |    ProjectX |       Paul |     201 |

Open in new window

see http://sqlfiddle.com/#!4/47b9f/2
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
awking00Information Technology SpecialistCommented:
You could also use the merge function -
merge into project p
using user u
on (p.projmanager = u.username)
when matched then
update set p.user_id = u.user_id;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.