I wanted to know how to write this query in Oracle SQL:
UPDATE address
SET phone1 = sp.phone,
is_avlbl = ( CASE
WHEN sp.name IS NULL THEN 1
ELSE 0
END )
FROM address ad
LEFT JOIN speaker sp
ON sp.addressid = ad.id
The above query format is from MS SQL Server but I want to achieve similar functionality with Oracle.
Already seen Update and left outer join statements, which is for T-SQL.
EDIT
I have tried the following solution:
update
table1 t1
set
(
t1.column1,
t1.column2,
t1.column3
) = (
select
t2.column1,
t2.column2,
( CASE
WHEN t2.column2 IS NULL THEN 1
ELSE 0
END )
from
table2 t2
where
t2.column1 = t1.column1
);
But the problem is that When there is no record in t2 corresponding to t1, then the above sql inserts null values into t1 where as i need some other value inserted into it when there is no such record. I apologize if this part of the requirement was not clear earlier.