# Database Discussions > Oracle >  Using Case and Joins in update statement

## valliv9

Hello everyone..!

I need to update a table by using both Join and case statements. I am not very good at SQL. Please find the code given below written by me...
update t1 a
set a.name2=
(case
when b.msg2 in ('bingo') then '1'
when b.msg2 in ('andrew') then '2'
when b.msg2 in ('sam') then '3'  
else '4'
end )
from t1 a left outer join t2 b
on a.name1 = b.msg1 ;

I am getting an error saying the SQL command not ended properly..Please help me...

I really appreciate your help !
Thanks in advance...  :Smilie:

----------


## Gladiator

Hi Buddy
I am also new to sql

But why do you need to use join in this particular case.
You can probably achieve the results by using the below code

UPDATE t1 a
    SET t1.name2 = 
    (CASE
         WHEN b.msg2 = 'bingo' THEN '1'
         WHEN b.msg2 = 'andrew' THEN '2'
         WHEN b.msg2 = 'sam' THEN '3'
         ELSE '4'
         END
    FROM t2 b
    WHERE a.name1=b.msg1);

----------

