I'm having some trouble joining the contents of two tables. I want 0 instead of NULL in the result. Here's the current situation:
table1
Name v1 v2
A 1 2
B 5 3
C 8 4
table2
Name v3 v4 Id
B 8 12 1
B 7 22 3
C 6 4 2
Result
Name v3 v4
A NULL NULL
B 8 12
C NULL NULL
Expected Result
Name v3 v4
A 0 0
B 8 12
C 0 0
I've tried the following to achieve the result:
select t1.Name,
(select coalesce(v3,0) from table2 where Name = t1.Name and id =1),
(select coalesce(v4,0) from table2 where Name= t1.Name and id =1)
from table1 t1